package com.wootion.cims.module.communitypersonal.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ser.Serializers;
import com.wootion.cims.dao.*;
import com.wootion.cims.general.utils.*;
import com.wootion.cims.module.basicinformation.plotsetting.model.Building;
import com.wootion.cims.module.basicinformation.plotsetting.model.BungalowVilla;
import com.wootion.cims.module.basicinformation.plotsetting.model.PlotMessage;
import com.wootion.cims.module.basicinformation.plotsetting.model.Unit;
import com.wootion.cims.module.communitypersonal.model.*;
import com.wootion.cims.module.communitypersonal.service.PersonService;
import com.wootion.cims.module.communityresidence.residencelist.model.Residence;
import com.wootion.cims.module.communityservice.dto.*;
import com.wootion.cims.module.systemsetting.community.model.SysCommunity;
import com.wootion.cims.module.systemsetting.log.model.SysLog;
import com.wootion.cims.module.systemsetting.polt.model.SysPlot;
import com.wootion.cims.module.systemsetting.user.model.SysUserRole;
import com.wootion.cims.module.systemsetting.user.model.User;
import com.wootion.cims.response.ResponseResult;
import com.wootion.cims.response.ResultCode;
import com.wootion.cims.shiro.utils.ShiroUtils;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@Slf4j
@Service
public class PersonServiceImpl extends  ServiceImpl<PersonDao, Person> implements PersonService {

    @Resource
    EasyExcelOrderListener easyExcelOrderListener;

    @Autowired(required = false)
    ResidenceDao residenceDao;

    @Autowired(required = false)
    PersonDao personDao;

    @Autowired(required = false)
    SysCommunityDao syscommunityDao;

    @Autowired(required = false)
    SysPlotDao sysplotDao;

    @Autowired(required = false)
    InportLogDao inportLogDao;

    @Autowired(required = false)
    PersonInputDao personInputDao;

    @Value("${cims.path}")
    private String dir;
    @Resource
    private SysUserRoleDao sysUserRoleDao;
    @Resource
    private SysRoleDao sysRoleDao;
    @Resource
    private SysUserCommunityDao sysUserCommunityDao;
    @Resource
    private SysCommunityDao sysCommunityDao;
    @Resource
    private SysPlotDao sysPlotDao;
    @Resource
    private SysLogDao sysLogDao;
    @Resource
    private ChackUtil chackUtil;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult insert(JSONObject jsonObject) {
        Person person = JSONObject.parseObject(jsonObject.toJSONString(), Person.class);
        //转换日期格式
        person = conversionDate(person);
        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id_number", person.getIdNumber());
        queryWrapper.eq("enabled", true);
        Person person1 = personDao.selectOne(queryWrapper);
        if (Optional.ofNullable(person1).isPresent()) {
            Residence residence = residenceDao.selectById(person.getAbodeId());
            SysCommunity sysCommunity = syscommunityDao.selectById(residence.getCommunityId());
            SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
            return ResponseResult.builder().code(ResultCode.WRONG_REQUEST_PARAMETER.getCode()).message("身份证号“" + person1.getIdNumber() + "”已关联居住地址“" + "河北省廊坊市三河市" + sysCommunity.getName() + sysPlot.getName() + residence.getHouseNumber() + "”，是否变更此人员的居住地址！").build();
        }


//        UUID uuid= UUID.randomUUID();
        person.setEnabled(true).setCreateTime(new Date());
        if (person.getAbodeId().equals("")) {
            person.setAbodeId(null);
        }
        person = mark(person);
        int insert = personDao.insert(person);

        if (insert > 0) {
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).build();
        } else {
            return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message(ResultCode.SYSTEM_ERROR.getMessage()).build();
        }
    }

    @Override
    public ResponseResult update(JSONObject jsonObject, HttpServletRequest request) {

        Person person = JSONObject.parseObject(jsonObject.toJSONString(), Person.class);
        //转换日期格式
        person = conversionDate(person);
        Person person1 = personDao.selectById(person.getId());
        if (Optional.ofNullable(person.getAbodeId()).isPresent()) {
            if (person.getAbodeId().equals("")) {
                person.setAbodeId("");
            }
        }

        if (Optional.ofNullable(person.getWz()).isPresent() && person.getWz().equals("完整") && Optional.ofNullable(person.getDrInset()).isPresent() &&  person.getDrInset().equals("0")){
            QueryWrapper<PersonInput> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("person_id",person.getId());
            PersonInput personInput = personInputDao.selectOne(queryWrapper2);
            personInput.setIsComp("完整");
            personInputDao.updateById(personInput);
        }

        person = mark(person);
        SysLog sysLog = new SysLog();
        sysLog.setIncident("个人信息");
        sysLog.setType("修改");
        sysLog.setValue("业务日志");
        sysLog.setCreateTime(new Date());
        sysLog.setIp(GetIp.getIpAddr(request));
        User user3 = (User) ShiroUtils.getSubject().getPrincipal();
        sysLog.setOperator(user3.getUsername());
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(person1.getName()).append("(").append(person1.getIdNumber()).append(")");
        sysLog.setContent(stringBuilder.toString());
        //person为当前要修改的（新）
        //person1为原本的信息（旧）
        StringBuilder builder = logPerson(person1, person);
        sysLog.setDetails(builder.toString());
        int i = personDao.updateById(person);

        if (i > 0) {
            sysLog.setResult("成功");
            int insert = sysLogDao.insert(sysLog);
            if (insert > 0) {
                log.info("个人信息修改记录日志成功!!!");
            } else {
                log.error("个人信息修改记录日志失败!!!");
            }
            Person person2 = personDao.selectById(person.getId());
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            if (Optional.ofNullable(person1.getAbodeId()).isPresent() && Optional.ofNullable(person.getAbodeId()).isPresent()) {
                if (!person1.getAbodeId().equals(person.getAbodeId()) || (StringUtil.isNullOrEmpty(person.getAbodeId()) && !StringUtil.isNullOrEmpty(person1.getAbodeId()))) {
                    person2.setLiveremark("");
                }
            }
            if (Optional.ofNullable(person1.getPlaceId()).isPresent() && Optional.ofNullable(person.getPlaceId()).isPresent()) {
                if (!person1.getPlaceId().equals(person.getPlaceId()) || (StringUtil.isNullOrEmpty(person.getPlaceId()) && !StringUtil.isNullOrEmpty(person1.getPlaceId()))) {
                    person2.setPlaceremark("");
                }
            }
            personDao.updateById(person2);
            if (isChageLog(person1, person)) {
                String s = chageLog(person1, person);
                if (Optional.ofNullable(person2.getChageDate()).isPresent()) {
                    PersonItem personItem = new PersonItem();
                    personItem.setDate(simpleDateFormat.format(new Date()));
                    User user = (User) ShiroUtils.getSubject().getPrincipal();
                    personItem.setPepole(user.getUsername());
                    personItem.setSj(s);
                    person2.getChageDate().add(personItem);
                } else {
                    person2.setChageDate(new ArrayList<>());
                    PersonItem personItem = new PersonItem();
                    personItem.setDate(simpleDateFormat.format(new Date()));
                    User user = (User) ShiroUtils.getSubject().getPrincipal();
                    personItem.setPepole(user.getUsername());
                    personItem.setSj(s);
                    person2.getChageDate().add(personItem);
                }
                personDao.updateById(person2);

            }
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).build();
        } else {
            sysLog.setResult("失败");
            int insert = sysLogDao.insert(sysLog);
            if (insert > 0) {
                log.info("个人信息修改记录日志成功!!!");
            } else {
                log.error("个人信息修改记录日志失败!!!");
            }
            return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message(ResultCode.SYSTEM_ERROR.getMessage()).build();
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult deleteById(String parseObject) {
        Person person = personDao.selectById(parseObject);
        int i = personDao.updateById(person.setEnabled(false));

        if (i > 0) {
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).build();
        } else {
            return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message(ResultCode.SYSTEM_ERROR.getMessage()).build();
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseResult deleteByIds(JSONObject ids) {
        JSONArray ids1 = ids.getJSONArray("ids");
        List<String> list2 = ids1.toJavaList(String.class);
        for (String id : list2) {
            Person person = personDao.selectById(id);
            if (Optional.ofNullable(person).isPresent()) {
                personDao.updateById(person.setEnabled(false));
            }
        }
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).build();
    }

    @Override
    public ResponseResult selectPage2(Integer page, Integer limit, String condition) {

        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        condition = condition.replaceAll("&quot;", "\"");

        JSONObject jsonObject1 = JSONObject.parseObject(condition);
        String com = jsonObject1.getString("liveCommunity");
        String plo = jsonObject1.getString("livePlot");
//        PersonQuery personQuery = JSONObject.parseObject(condition, PersonQuery.class);
        QueryWrapper<InportLog> personQueryWrapper = new QueryWrapper<>();


        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper.in("community_id", commnityIds);
                queryWrapper.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper);
            } else {

            }

            for (Residence residence : residences) {
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }


////        复杂查询
//        if (Optional.ofNullable(personQuery).isPresent()) {
//            Date begintime1 = null;
//            Date endtime1 = null;
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//            try {
//                if (Optional.ofNullable(personQuery.getBegintime()).isPresent()) {
//                    begintime1 = simpleDateFormat.parse(personQuery.getBegintime());
//                }
//                if (Optional.ofNullable(personQuery.getEndtime()).isPresent()) {
//                    endtime1 = simpleDateFormat.parse(personQuery.getEndtime());
//                }
//            } catch (ParseException e) {
//                e.printStackTrace();
//            }
//
//            //创建时间
////            QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
//            if (Optional.ofNullable(personQuery.getBegintime()).isPresent()) {
//                personQueryWrapper.between("birth_time", begintime1, endtime1);
//            }
//            //关键字
//            if (Optional.ofNullable(personQuery.getKeyWord()).isPresent()) {
//                personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.like("name", personQuery.getKeyWord()).or().like("tel", personQuery.getKeyWord())
//                        .or().like("id_number", personQuery.getKeyWord()));
//            }
//            //性别
//            if (Optional.ofNullable(personQuery.getGender()).isPresent()) {
//                personQueryWrapper.eq("gender", personQuery.getGender());
//            }
//            //民族
//            if (Optional.ofNullable(personQuery.getNation()).isPresent()) {
//                personQueryWrapper.eq("nation", personQuery.getNation());
//            }
//            //户籍编号
//            if (Optional.ofNullable(personQuery.getHouseNumber()).isPresent()) {
//                personQueryWrapper.eq("house_number", personQuery.getHouseNumber());
//            }
//
//            Queue<String> queue = new ArrayDeque<>();
//            if (personQuery.getInformation() != null) {
//                if (!personQuery.getInformation().isEmpty()) {
//                    for (String s : personQuery.getInformation()) {
//                        if (s.equals("租户")) {
//                            queue.add("tent_inset");
//                        }
//                        if (s.equals("老年人")) {
//                            queue.add("oldman_inset");
//                        }
//                        if (s.equals("残疾人")) {
//                            queue.add("defor_inset");
//                        }
//                        if (s.equals("党员")) {
//                            queue.add("part_inset");
//                        }
//                        if (s.equals("低保")) {
//                            queue.add("under_inset");
//                        }
//                        if (s.equals("优抚")) {
//                            queue.add("care_inset");
//                        }
//                    }
//                }
//                personQueryWrapper = PackSql(personQueryWrapper, queue, personQuery.getInformation().size());
//            }

            //居住地
        if (Optional.ofNullable(com).isPresent() && !StringUtil.isNullOrEmpty(com)) {
            personQueryWrapper.eq("residence_id",com);
        }
            //户籍地
        if (Optional.ofNullable(plo).isPresent() && !StringUtil.isNullOrEmpty(plo)) {
            personQueryWrapper.eq("plot_id",plo);
        }
//        }


////        地区和权限筛选
//        if (stringList.size() > 0) {
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().isNull("abode_id"));
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id", ""));
//        } else if ("street:admin".equals(roleKey)) {
//        } else {
//            personQueryWrapper.eq("abode_id", "");
//        }

//        if (stringList2.size()>0) {
//            personQueryWrapper.in("place_id", stringList2);
//        }else if ("street:admin".equals(roleKey)){
//
//        }else {
//            stringList2.add("哈哈哈");
//            personQueryWrapper.in("place_id", stringList2);
//        }


        Page<InportLog> page1 = new Page<>(page, limit);
//        personQueryWrapper.eq("enabled", true);
        personQueryWrapper.orderByDesc("create_time");
        Page<InportLog> personPage = inportLogDao.selectPage(page1, personQueryWrapper);


//        //处理结果集
//        List<JSONObject> jsonObjects = new ArrayList<>();
////        for (Person person : personPage.getRecords()) {
////            boolean a = false;
////            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(person));
////
////            List<String> list = new ArrayList<>();
////            StringBuilder stringBuilder = new StringBuilder();
////            if (person.getOldmanInset().equals("true")) {
////                list.add("老年人");
////            }
////
////            if (person.getDeforInset().equals("true")) {
////                list.add("残疾人");
////            }
////            if (person.getUnderInset().equals("true")) {
////                list.add("低保");
////            }
////
////            if (person.getCareInset().equals("true")) {
////                list.add("优抚");
////            }
////
////            if (person.getPartInset().equals("true")) {
////                list.add("党员");
////            }
////
////            if (person.getTentInset().equals("true")) {
////                list.add("租户");
////            }
////            int i = 0;
////            for (String s : list) {
////                if (i != 0) {
////                    stringBuilder.append(",");
////                }
////                stringBuilder.append(s);
////                i++;
////            }
////
////            jsonObject.put("information3", stringBuilder.toString());
////
////            if (person.getInside2()) {
////                Residence residence = residenceDao.selectById(person.getAbodeId());
////                if (Optional.ofNullable(residence).isPresent()) {
////
////                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
////                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
////                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
////                    jsonObject.put("abode_address", s);
////                }
////            } else {
////                String s = person.getOut2Province() + person.getOut2City() + person.getOut2FullAddress();
////                if (s.equals("nullnullnull")) {
////                    s = " ";
////                }
////                jsonObject.put("abode_address", s);
////            }
////            if (person.getInside1()) {
////                Residence residence = residenceDao.selectById(person.getPlaceId());
////                if (Optional.ofNullable(residence).isPresent()) {
////                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
////                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
////                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
////                    jsonObject.put("place_address", s);
////                }
////            } else {
////                String s = person.getOut1Province() + person.getOut1City() + person.getOut1FullAddress();
////                if (s.equals("nullnullnull")) {
////                    s = " ";
////                }
////                jsonObject.put("place_address", s);
////            }
////            jsonObjects.add(jsonObject);
////        }
//
//        Page<JSONObject> page2 = new Page<>();
//        page2.setPages(personPage.getPages());
//        page2.setMaxLimit(personPage.getMaxLimit());
//        page2.setRecords(jsonObjects);
//        page2.setSize(personPage.getSize());
//        page2.setCurrent(personPage.getCurrent());
//        page2.setTotal(personPage.getTotal());
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(personPage).build();
    }

    @Override
    public ResponseResult selectPage3(Integer page, Integer limit, String condition) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        condition = condition.replaceAll("&quot;", "\"");
        PersonQuery personQuery = JSONObject.parseObject(condition, PersonQuery.class);
        QueryWrapper<PersonInput> personinputQueryWrapper = new QueryWrapper<>();


        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper.in("community_id", commnityIds);
                queryWrapper.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper);
            } else {

            }

            for (Residence residence : residences) {
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }


//        复杂查询
        if (Optional.ofNullable(personQuery).isPresent()) {
            QueryWrapper<PersonInput> queryWrapper = new QueryWrapper<>();
            if (Optional.ofNullable(personQuery.getKeyWord()).isPresent() && !StringUtil.isNullOrEmpty(personQuery.getKeyWord())) {
                personinputQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.like("name", personQuery.getKeyWord()).or().like("tel", personQuery.getKeyWord())
                        .or().like("id_number", personQuery.getKeyWord()));
            }
            if (Optional.ofNullable(personQuery.getLiveCommunity()).isPresent() && !StringUtil.isNullOrEmpty(personQuery.getLiveCommunity())) {
                personinputQueryWrapper.eq("com_id", personQuery.getLiveCommunity());
            }
            if (Optional.ofNullable(personQuery.getLivePlot()).isPresent() && !StringUtil.isNullOrEmpty(personQuery.getLivePlot())) {
                personinputQueryWrapper.eq("plot_id", personQuery.getLivePlot());
            }
            if (Optional.ofNullable(personQuery.getIsCom()).isPresent() && !StringUtil.isNullOrEmpty(personQuery.getIsCom())) {
                personinputQueryWrapper.eq("is_comp", personQuery.getIsCom());
            }
        }


//        地区和权限筛选
        if (stringList.size() > 0) {
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().isNull("abode_id"));
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id", ""));

            personinputQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("com_id", stringList));
            personinputQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("plot_id", stringList));
//            personQueryWrapper.eq("place_id","");
        } else if ("street:admin".equals(roleKey)) {

        }
//        else {
////            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","")
////                    .or().eq("place_id","")
////            personQueryWrapper.eq("abode_id", "");
////            personQueryWrapper.isNull("abode_id");
//        }

//        if (stringList2.size()>0) {
//            personQueryWrapper.in("place_id", stringList2);
//        }else if ("street:admin".equals(roleKey)){
//
//        }else {
//            stringList2.add("哈哈哈");
//            personQueryWrapper.in("place_id", stringList2);
//        }


        Page<PersonInput> page1 = new Page<>(page, limit);
//        personQueryWrapper.eq("enabled", true);
        Page<PersonInput> personPage = personInputDao.selectPage(page1, personinputQueryWrapper);


        //处理结果集
        List<Person> people = new ArrayList<>();
        for (PersonInput person : personPage.getRecords()) {
            Person person1 = personDao.selectById(person.getPersonId());
            people.add(person1);
        }
        List<JSONObject> jsonObjects = new ArrayList<>();
        for (Person person : people) {
            boolean a = false;
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(person));

            List<String> list = new ArrayList<>();
            StringBuilder stringBuilder = new StringBuilder();
            if (person.getOldmanInset().equals("true")) {
                list.add("老年人");
            }

            if (person.getDeforInset().equals("true")) {
                list.add("残疾人");
            }

            if (person.getUnderInset().equals("true")) {
                list.add("低保");
            }

            if (person.getCareInset().equals("true")) {
                list.add("优抚");
            }

            if (person.getPartInset().equals("true")) {
                list.add("党员");
            }

            if (person.getTentInset().equals("true")) {
                list.add("租户");
            }
            int i = 0;
            for (String s : list) {
                if (i != 0) {
                    stringBuilder.append(",");
                }
                stringBuilder.append(s);
                i++;
            }

            jsonObject.put("information3", stringBuilder.toString());

//            if (person.getInside2()) {
//                Residence residence = residenceDao.selectById(person.getAbodeId());
//                if (Optional.ofNullable(residence).isPresent()) {
//
//                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
//                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
//                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
//                    jsonObject.put("abode_address", s);
//                }
//            } else {
//                String s = person.getOut2Province() + person.getOut2City() + person.getOut2FullAddress();
//                if (s.equals("nullnullnull")) {
//                    s = " ";
//                }
//                jsonObject.put("abode_address", s);
//            }
//            if (person.getInside1()) {
//                Residence residence = residenceDao.selectById(person.getPlaceId());
//                if (Optional.ofNullable(residence).isPresent()) {
//                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
//                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
//                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
//                    jsonObject.put("place_address", s);
//                }
//            } else {
//                String s = person.getOut1Province() + person.getOut1City() + person.getOut1FullAddress();
//                if (s.equals("nullnullnull")) {
//                    s = " ";
//                }
//                jsonObject.put("place_address", s);
//            }
            QueryWrapper<PersonInput> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("person_id",person.getId());
            PersonInput personInput = personInputDao.selectOne(queryWrapper);
            if (Optional.ofNullable(personInput).isPresent()){
//                jsonObject.put("tradeName",personInput.getTradeName());
                jsonObject.put("com",personInput.getComId());
                jsonObject.put("plo",personInput.getPlotId());
            }

            if (Optional.ofNullable(person.getAbodeId()).isPresent()){
                Residence residence = residenceDao.selectById(person.getAbodeId());
                jsonObject.put("abode",residence);
            }

                if(StringUtils.hasText(person.getAbodeId())) {
                    Residence residence = residenceDao.selectById(person.getAbodeId());
                    JSONObject jsonObject2 = JSONObject.parseObject(JSONObject.toJSONString(residence));
                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                    jsonObject2.put("plot_name", sysPlot.getName());
                    SysCommunity sysCommunity = syscommunityDao.selectById(residence.getCommunityId());
                    jsonObject2.put("com_name", sysCommunity.getName());

                    SysPlot sysPlot2 = sysPlotDao.selectById(residence.getPlotId());
                    String address = residence.getAddress();
                    List<String> addrArray = new LinkedList<>();
                    if (residence.getCategory().equals("平房/别墅")) {
                        String bungalowVilla = sysPlot2.getBungalowVilla();
                        PlotMessage plotMessage = JSON.parseObject(bungalowVilla, PlotMessage.class);
                        List<BungalowVilla> bungalowVillas = plotMessage.getBungalowVillas();
                        for (BungalowVilla villa : bungalowVillas) {
                            if (villa.getArea().equals(address)) {
                                addrArray.add(villa.getId());
                                break;
                            }
                        }
                    }
                    String[] strings = address.split("/");
                    String buildingUnit = sysPlot2.getBuildingUnit();
                    PlotMessage plotMessage = JSON.parseObject(buildingUnit, PlotMessage.class);
                    List<Building> buildings = plotMessage.getBuildings();
                    for (Building building : buildings) {
                        if (building.getStoriedBuilding().equals(strings[0])) {
                            addrArray.add(building.getId());
                            List<Unit> units = building.getUnits();
                            for (Unit unit : units) {
                                if (unit.getUnit().equals(strings[1])) {
                                    addrArray.add(unit.getId());
                                    break;
                                }
                            }
                        }
                    }
                    jsonObject2.put("addrArray", addrArray);
                    //jsonObject.put("addrArray", addrArray);

                    jsonObject.put("abode", jsonObject2);
                }


            if (person.getInside2()&& Optional.ofNullable(person.getAbodeId()).isPresent() &&!StringUtil.isNullOrEmpty(person.getAbodeId())) {
                Residence residence = residenceDao.selectById(person.getAbodeId());
                if (Optional.ofNullable(residence).isPresent()) {

                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
                    jsonObject.put("abode_address", s);
                }
            } else {
                String s = person.getOut2Province() + person.getOut2City() + person.getOut2FullAddress();
                if (s.equals("nullnullnull")) {
                    s = " ";
                }
                jsonObject.put("abode_address", s);
            }
            if (person.getInside1()&& Optional.ofNullable(person.getPlaceId()).isPresent() &&!StringUtil.isNullOrEmpty(person.getPlaceId())) {
                Residence residence = residenceDao.selectById(person.getPlaceId());
                if (Optional.ofNullable(residence).isPresent()) {
                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
                    jsonObject.put("place_address", s);
                }
            } else {
                String s = person.getOut1Province() + person.getOut1City() + person.getOut1FullAddress();
                if (s.equals("nullnullnull")) {
                    s = " ";
                }
                jsonObject.put("place_address", s);
            }

            if (person.getInside1() && person.getWz().equals("完整") && Optional.ofNullable(person.getPlaceId()).isPresent() && !StringUtil.isNullOrEmpty(person.getPlaceId())) {
                Residence residence = residenceDao.selectById(person.getPlaceId());
                JSONObject jsonObject3 = JSONObject.parseObject(JSONObject.toJSONString(residence));
                SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                jsonObject3.put("plot_name", sysPlot.getName());
                SysCommunity sysCommunity = syscommunityDao.selectById(residence.getCommunityId());
                jsonObject3.put("com_name", sysCommunity.getName());
                if (residence.getCategory().equals("楼房")) {
                    jsonObject3.put("addrArray", residence.getAddress().split("/"));
                }

                SysPlot sysPlot2 = sysPlotDao.selectById(residence.getPlotId());
                String address = residence.getAddress();
                List<String> addrArray = new LinkedList<>();
                if (residence.getCategory().equals("平房/别墅")) {
                    String bungalowVilla = sysPlot2.getBungalowVilla();
                    PlotMessage plotMessage = JSON.parseObject(bungalowVilla, PlotMessage.class);
                    List<BungalowVilla> bungalowVillas = plotMessage.getBungalowVillas();
                    for (BungalowVilla villa : bungalowVillas) {
                        if (villa.getArea().equals(address)) {
                            addrArray.add(villa.getId());
                            break;
                        }
                    }
                }
                String[] strings = address.split("/");
                String buildingUnit = sysPlot2.getBuildingUnit();
                PlotMessage plotMessage = JSON.parseObject(buildingUnit, PlotMessage.class);
                List<Building> buildings = plotMessage.getBuildings();
                for (Building building : buildings) {
                    if (building.getStoriedBuilding().equals(strings[0])) {
                        addrArray.add(building.getId());
                        List<Unit> units = building.getUnits();
                        for (Unit unit : units) {
                            if (unit.getUnit().equals(strings[1])) {
                                addrArray.add(unit.getId());
                                break;
                            }
                        }
                    }
                }
                jsonObject3.put("addrArray", addrArray);

                jsonObject.put("place", jsonObject3);
            }

            jsonObjects.add(jsonObject);
        }



        Page<JSONObject> page2 = new Page<>();
        page2.setPages(personPage.getPages());
        page2.setMaxLimit(personPage.getMaxLimit());
        page2.setRecords(jsonObjects);
        page2.setSize(personPage.getSize());
        page2.setCurrent(personPage.getCurrent());
        page2.setTotal(personPage.getTotal());
        List<JSONObject> jsonObjects1 = page2.getRecords();
        for (JSONObject jsonObject : jsonObjects1) {
//            jsonObject.put("")
        }

        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(page2).build();
    }

    @Override
    public ResponseResult inport(MultipartFile file, String abode, String communityId, String plotId) {
        BaseContext.setLocalCommunityId(communityId);
        BaseContext.setLocalPlotId(plotId);
        BaseContext.setLocalAbode(abode);
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
//        String fileName = "./人员导入-辖区内.xlsx";//文件路径
        //默认读取第一个sheet
//        EasyExcelOrderListener easyExcelOrderListener = new EasyExcelOrderListener();
        EasyExcel.read(inputStream, ExcelOrder.class, easyExcelOrderListener).sheet().doRead();

        //错误信息集合
        List<JSONObject> list = easyExcelOrderListener.getSlist();
        //失败的数据集合
        List<ExcelOrder> elist = easyExcelOrderListener.getElist();
        //成功的数据集合
        List<Person> people = easyExcelOrderListener.getPeople();

        Integer integer = easyExcelOrderListener.getI()-1;
        int i = integer - elist.size();

        DateTimeFormatter ofPattern = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String format = LocalDateTime.now().format(ofPattern);

        String s = excelWrite(elist,format+"_"+elist.size()+"失败数"+UUID.randomUUID());

        for (Person person : people) {

            if (Optional.ofNullable(person.getPlace()).isPresent() && !StringUtil.isNullOrEmpty(person.getPlace())){
                if(person.getPlace().equals("辖区内")) {
                    person.setInside1(true);
                }else {
                    person.setInside1(false);
                }
            }else {
                person.setInside1(false).setPlace("辖区外/集体户");
            }


            if (abode.equals("辖区外")){
                person.setEnabled(true).setDrInset(null).setInside2(false).setAbode("辖区外").setDrInset("");
                personDao.updateById(person);
            }else {
                PersonInput personInput =new PersonInput();
                personInput.setComId(communityId).setPlotId(plotId).setTradeName(person.getAbode()).setPersonId(person.getId())
                .setName(person.getName()).setTel(person.getTel()).setIdNumber(person.getIdNumber());
                person.setInside2(true).setAbode("辖区内");
                if(!StringUtil.isNullOrEmpty(person.getTradeName())) {
                    boolean b = chackUtil.checkAddress(person.getTradeName(), communityId, plotId, abode);
                    if (b) {
                        personInput.setIsComp("完整");
                        person.setWz("完整");
                    } else {
                        personInput.setIsComp("缺失");
                        person.setWz("缺失");
                    }
                }else {
                    personInput.setIsComp("缺失");
                    person.setWz("缺失");
                }
                personDao.updateById(person);
                personInputDao.insert(personInput);
            }

        }

        InportLog inportLog = new InportLog();
        inportLog.setSuccess(i+"");
        inportLog.setFail(elist.size()+"");
        inportLog.setCount(integer+"");
        inportLog.setBclj(s);
        inportLog.setCreateTime(new Date());
        if (abode.equals("辖区内")){
            inportLog.setPlace("辖区内");
            inportLog.setPlot(sysplotDao.selectById(plotId).getName());
            inportLog.setResidence(sysCommunityDao.selectById(communityId).getName());
            inportLog.setPlotId(plotId);
            inportLog.setResidenceId(communityId);
        }else {
            inportLog.setPlace("辖区外");
        }
        inportLogDao.insert(inportLog);
        easyExcelOrderListener.setElist(new ArrayList<>());
        easyExcelOrderListener.setPeople(new ArrayList<>());
        easyExcelOrderListener.setSlist(new ArrayList<>());
        easyExcelOrderListener.setI(1);
        easyExcelOrderListener.setCout(0);
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(list).build();
    }

    @Override
    public ResponseResult inputs(JSONObject jsonObject) {

        List<String> list1 = new ArrayList<>();

        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

//        if (jsonObject.getString("type").equals("全部")){
        if (Optional.ofNullable(jsonObject.getString("type")).isPresent()){
            QueryWrapper<PersonInput> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("is_comp","完整");

            User user = (User) ShiroUtils.getSubject().getPrincipal();
            LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
            lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
            SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
            String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
            if (!"street:admin".equals(roleKey)) {
                List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
                if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                    return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
                }
                List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
                List<String> ids = new ArrayList<>();
                for (SysCommunity community : communities) {
                    ids.add(community.getId());
                }
                QueryWrapper<Residence> queryWrapper = new QueryWrapper<>();
                List<Residence> residences = new ArrayList<>();
                if (!commnityIds.isEmpty()) {
                    queryWrapper.in("community_id", commnityIds);
                    queryWrapper.eq("enabled", true);
                    residences = residenceDao.selectList(queryWrapper);
                } else {

                }

                for (Residence residence : residences) {
                    stringList.add(residence.getId());
                    stringList2.add(residence.getId());
                }
            }

            if (stringList.size() > 0) {
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().isNull("abode_id"));
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id", ""));

                queryWrapper2.and(personQueryWrapper1 -> personQueryWrapper1.in("com_id", stringList));
                queryWrapper2.and(personQueryWrapper1 -> personQueryWrapper1.in("plot_id", stringList));
//            personQueryWrapper.eq("place_id","");
            } else if ("street:admin".equals(roleKey)) {

            }

            List<PersonInput> personInputs = personInputDao.selectList(queryWrapper2);

            for (PersonInput personInput : personInputs) {
                Person person = personDao.selectById(personInput.getPersonId());
                if (person.getWz().equals("完整")) {
                    person.setEnabled(true).setDrInset(null).setWz(null);

                    if (Optional.ofNullable(person.getAbodeId()).isPresent() && !StringUtil.isNullOrEmpty(person.getAbodeId())){
                        person.setInside2(true);
                    }else {
                        person.setInside2(false);
                    }

                    personDao.updateById(person);
                    personInputDao.deleteById(personInput.getId());
                }else {
                    list1.add(person.getName());
                }
            }
        }else {
            JSONArray ids = jsonObject.getJSONArray("ids");
            List<String> list = ids.toJavaList(String.class);
            for (String s : list) {
                Person person = personDao.selectById(s);
                if (person.getWz().equals("完整")) {
                    QueryWrapper<PersonInput> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("person_id", person.getId());
                    PersonInput personInput = personInputDao.selectOne(queryWrapper);
                    person.setEnabled(true).setDrInset("").setWz("");

                    if (Optional.ofNullable(person.getAbodeId()).isPresent() && !StringUtil.isNullOrEmpty(person.getAbodeId())){
                        person.setInside2(true);
                    }else {
                        person.setInside2(false);
                    }
                    personDao.updateById(person);
                    personInputDao.deleteById(personInput.getId());
                 }else {
                    list1.add(person.getName());
                }
            }

        }
        if (list1.isEmpty()) {
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).build();
        }else {
            return ResponseResult.builder().code(ResultCode.WRONG_REQUEST_PARAMETER.getCode()).message(ResultCode.WRONG_REQUEST_PARAMETER.getMessage()).data(list1).build();
        }
    }

    @Override
    public ResponseResult selectPage4(String condition) {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        condition = condition.replaceAll("&quot;", "\"");
        PersonQuery personQuery = JSONObject.parseObject(condition, PersonQuery.class);
        QueryWrapper<PersonInput> personinputQueryWrapper = new QueryWrapper<>();


        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper.in("community_id", commnityIds);
                queryWrapper.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper);
            } else {

            }

            for (Residence residence : residences) {
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }


//        复杂查询
        if (Optional.ofNullable(personQuery).isPresent()) {
            QueryWrapper<PersonInput> queryWrapper = new QueryWrapper<>();
            if (Optional.ofNullable(personQuery.getKeyWord()).isPresent() &&! StringUtil.isNullOrEmpty(personQuery.getKeyWord())) {
                personinputQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.like("name", personQuery.getKeyWord()).or().like("tel", personQuery.getKeyWord())
                        .or().like("id_number", personQuery.getKeyWord()));
            }
            if (Optional.ofNullable(personQuery.getLiveCommunity2()).isPresent() &&! StringUtil.isNullOrEmpty(personQuery.getKeyWord())) {
                personinputQueryWrapper.eq("com_id", personQuery.getLiveCommunity2());
            }
            if (Optional.ofNullable(personQuery.getLivePlot2()).isPresent() &&! StringUtil.isNullOrEmpty(personQuery.getKeyWord())) {
                personinputQueryWrapper.eq("plot_id", personQuery.getLivePlot2());
            }
            if (Optional.ofNullable(personQuery.getIsCom()).isPresent() &&! StringUtil.isNullOrEmpty(personQuery.getKeyWord())){
                personinputQueryWrapper.eq("wz", personQuery.getIsCom());
            }
        }


//        地区和权限筛选
        if (stringList.size() > 0) {
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().isNull("abode_id"));
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id", ""));

            personinputQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("com_id", stringList));
            personinputQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("plot_id", stringList));
//            personQueryWrapper.eq("place_id","");
        } else if ("street:admin".equals(roleKey)) {

        }
//        else {
////            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","")
////                    .or().eq("place_id","")
////            personQueryWrapper.eq("abode_id", "");
////            personQueryWrapper.isNull("abode_id");
//        }

//        if (stringList2.size()>0) {
//            personQueryWrapper.in("place_id", stringList2);
//        }else if ("street:admin".equals(roleKey)){
//
//        }else {
//            stringList2.add("哈哈哈");
//            personQueryWrapper.in("place_id", stringList2);
//        }


//        Page<PersonInput> page1 = new Page<>(page, limit);
//        personQueryWrapper.eq("enabled", true);
        List<PersonInput> personInputs = personInputDao.selectList(personinputQueryWrapper);


        //处理结果集
        List<Person> people = new ArrayList<>();
        for (PersonInput person : personInputs) {
            Person person1 = personDao.selectById(person.getPersonId());
            people.add(person1);
        }
        List<JSONObject> jsonObjects = new ArrayList<>();
        for (Person person : people) {
            boolean a = false;
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(person));

            List<String> list = new ArrayList<>();
            StringBuilder stringBuilder = new StringBuilder();
            if (person.getOldmanInset().equals("true")) {
                list.add("老年人");
            }

            if (person.getDeforInset().equals("true")) {
                list.add("残疾人");
            }
            if (person.getUnderInset().equals("true")) {
                list.add("低保");
            }

            if (person.getCareInset().equals("true")) {
                list.add("优抚");
            }

            if (person.getPartInset().equals("true")) {
                list.add("党员");
            }

            if (person.getTentInset().equals("true")) {
                list.add("租户");
            }
            int i = 0;
            for (String s : list) {
                if (i != 0) {
                    stringBuilder.append(",");
                }
                stringBuilder.append(s);
                i++;
            }

            jsonObject.put("information3", stringBuilder.toString());

//            if (person.getInside2()) {
//                Residence residence = residenceDao.selectById(person.getAbodeId());
//                if (Optional.ofNullable(residence).isPresent()) {
//
//                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
//                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
//                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
//                    jsonObject.put("abode_address", s);
//                }
//            } else {
//                String s = person.getOut2Province() + person.getOut2City() + person.getOut2FullAddress();
//                if (s.equals("nullnullnull")) {
//                    s = " ";
//                }
//                jsonObject.put("abode_address", s);
//            }
//            if (person.getInside1()) {
//                Residence residence = residenceDao.selectById(person.getPlaceId());
//                if (Optional.ofNullable(residence).isPresent()) {
//                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
//                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
//                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
//                    jsonObject.put("place_address", s);
//                }
//            } else {
//                String s = person.getOut1Province() + person.getOut1City() + person.getOut1FullAddress();
//                if (s.equals("nullnullnull")) {
//                    s = " ";
//                }
//                jsonObject.put("place_address", s);
//            }
            jsonObjects.add(jsonObject);
        }
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObjects).build();
    }

    @Override
    public ResponseResult getNumber() {
        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        QueryWrapper<PersonInput> personinputQueryWrapper = new QueryWrapper<>();


        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper.in("community_id", commnityIds);
                queryWrapper.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper);
            } else {

            }

            for (Residence residence : residences) {
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }


//        复杂查询
        personinputQueryWrapper.eq("is_comp", "完整");


//        地区和权限筛选
        if (stringList.size() > 0) {
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().isNull("abode_id"));
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id", ""));

            personinputQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("com_id", stringList));
            personinputQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("plot_id", stringList));
//            personQueryWrapper.eq("place_id","");
        } else if ("street:admin".equals(roleKey)) {

        }
//        else {
////            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","")
////                    .or().eq("place_id","")
////            personQueryWrapper.eq("abode_id", "");
////            personQueryWrapper.isNull("abode_id");
//        }

//        if (stringList2.size()>0) {
//            personQueryWrapper.in("place_id", stringList2);
//        }else if ("street:admin".equals(roleKey)){
//
//        }else {
//            stringList2.add("哈哈哈");
//            personQueryWrapper.in("place_id", stringList2);
//        }


//        Page<PersonInput> page1 = new Page<>(page, limit);
//        personQueryWrapper.eq("enabled", true);
        List<PersonInput> personInputs = personInputDao.selectList(personinputQueryWrapper);

        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(personInputs.size()).build();
    }

    @Override
    public ResponseResult updates(JSONObject jsonObject,HttpServletRequest request) {
        JSONArray ids = jsonObject.getJSONArray("ids");
        List<String> list = ids.toJavaList(String.class);
        for (String string : list) {
            Person person = personDao.selectById(string);
            //转换日期格式
            person = conversionDate(person);
            Person person1 = personDao.selectById(person.getId());
            if (Optional.ofNullable(person.getAbodeId()).isPresent()) {
                if (person.getAbodeId().equals("")) {
                    person.setAbodeId("");
                }
            }
            person = mark(person);
            person.setAbodeId(jsonObject.getString("lid"));

            if (Optional.ofNullable(person.getAbodeId()).isPresent()){
                if (person.getWz().equals("缺失")){
                    person.setWz("完整");
                    QueryWrapper<PersonInput> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("person_id",person.getId());
                    PersonInput personInput = personInputDao.selectOne(queryWrapper);
                    personInput.setIsComp("完整");
                    personInputDao.updateById(personInput);
                }
            }

            SysLog sysLog = new SysLog();
            sysLog.setIncident("个人信息");
            sysLog.setType("修改");
            sysLog.setValue("业务日志");
            sysLog.setCreateTime(new Date());
            sysLog.setIp(GetIp.getIpAddr(request));
            User user3 = (User) ShiroUtils.getSubject().getPrincipal();
            sysLog.setOperator(user3.getUsername());
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(person1.getName()).append("(").append(person1.getIdNumber()).append(")");
            sysLog.setContent(stringBuilder.toString());
            //person为新当前要修改的
            //person1为原本的信息
            StringBuilder builder = logPerson(person1, person);
            sysLog.setDetails(builder.toString());


            int i = personDao.updateById(person);
            if (i > 0) {
                sysLog.setResult("成功");
                int insert = sysLogDao.insert(sysLog);
                if (insert > 0) {
                    log.info("个人信息修改记录日志成功!!!");
                } else {
                    log.error("个人信息修改记录日志失败!!!");
                }
                Person person2 = personDao.selectById(person.getId());
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                if (Optional.ofNullable(person1.getAbodeId()).isPresent() && Optional.ofNullable(person1.getAbodeId()).isPresent()) {
                    if (!person1.getAbodeId().equals(person.getAbodeId()) || (StringUtil.isNullOrEmpty(person.getAbodeId()) && !StringUtil.isNullOrEmpty(person1.getAbodeId()))) {
                        person2.setLiveremark("");
                    }
                }
                if (Optional.ofNullable(person1.getPlaceId()).isPresent() && Optional.ofNullable(person1.getPlaceId()).isPresent()) {
                    if (!person1.getPlaceId().equals(person.getPlaceId()) || (StringUtil.isNullOrEmpty(person.getPlaceId()) && !StringUtil.isNullOrEmpty(person1.getPlaceId()))) {
                        person2.setPlaceremark("");
                    }
                }
                personDao.updateById(person2);
                if (isChageLog(person1, person)) {
                    String s = chageLog(person1, person);
                    if (Optional.ofNullable(person2.getChageDate()).isPresent()) {
                        PersonItem personItem = new PersonItem();
                        personItem.setDate(simpleDateFormat.format(new Date()));
                        User user = (User) ShiroUtils.getSubject().getPrincipal();
                        personItem.setPepole(user.getUsername());
                        personItem.setSj(s);
                        person2.getChageDate().add(personItem);
                    } else {
                        person2.setChageDate(new ArrayList<>());
                        PersonItem personItem = new PersonItem();
                        personItem.setDate(simpleDateFormat.format(new Date()));
                        User user = (User) ShiroUtils.getSubject().getPrincipal();
                        personItem.setPepole(user.getUsername());
                        personItem.setSj(s);
                        person2.getChageDate().add(personItem);
                    }
                    personDao.updateById(person2);

                }

            } else {
                sysLog.setResult("失败");
                int insert = sysLogDao.insert(sysLog);
                if (insert > 0) {
                    log.info("个人信息修改记录日志成功!!!");
                } else {
                    log.error("个人信息修改记录日志失败!!!");
                }
                return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message(ResultCode.SYSTEM_ERROR.getMessage()).build();
            }
        }
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).build();
    }

    @Override
    public ResponseResult deleteInportById(String id) {
        Person person = personDao.selectById(id);
        QueryWrapper<PersonInput> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("person_id",person.getId());
        int delete = personInputDao.delete(queryWrapper);
        personDao.deleteById(person.getId());
//        InportLog inportLog = inportLogDao.selectById(id);
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).build();
    }

    @Override
    public ResponseResult input2(JSONObject jsonObject) {
        JSONArray ids = jsonObject.getJSONArray("ids");
        List<String> list = ids.toJavaList(String.class);
        for (String s : list) {
            Person person = personDao.selectById(s);
            person.setEnabled(true).setDrInset("").setWz("").setInside1(false);
            person.setAbodeId(jsonObject.getString("lid"));

            if (Optional.ofNullable(person.getAbodeId()).isPresent() && !StringUtil.isNullOrEmpty(person.getAbodeId())){
                person.setInside2(true);
            }else {
                person.setInside2(false);
            }

            personDao.updateById(person);
            QueryWrapper<PersonInput> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("person_id",person.getId());
            int delete = personInputDao.delete(queryWrapper);
        }

        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).build();
    }

    @Override
    public ResponseResult selectPage(Integer page, Integer limit, String condition) {

        List<String> stringList = new ArrayList<>();

        List<String> stringList2 = new ArrayList<>();

        condition = condition.replaceAll("&quot;", "\"");
        PersonQuery personQuery = JSONObject.parseObject(condition, PersonQuery.class);
        QueryWrapper<Person> personQueryWrapper = new QueryWrapper<>();


        //权限筛选
        //获取当前登陆人的信息
        User user = (User) ShiroUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
        SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
        String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
        if (!"street:admin".equals(roleKey)) {
            List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
            if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
            }
            List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
            List<String> ids = new ArrayList<>();
            for (SysCommunity community : communities) {
                ids.add(community.getId());
            }
            QueryWrapper<Residence> queryWrapper = new QueryWrapper<>();
            List<Residence> residences = new ArrayList<>();
            if (!commnityIds.isEmpty()) {
                queryWrapper.in("community_id", commnityIds);
                queryWrapper.eq("enabled", true);
                residences = residenceDao.selectList(queryWrapper);
            } else {

            }

            for (Residence residence : residences) {
                stringList.add(residence.getId());
                stringList2.add(residence.getId());
            }
        }


//        复杂查询
        if (Optional.ofNullable(personQuery).isPresent()) {
            Date begintime1 = null;
            Date endtime1 = null;
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                if (Optional.ofNullable(personQuery.getBegintime()).isPresent()) {
                    begintime1 = simpleDateFormat.parse(personQuery.getBegintime());
                }
                if (Optional.ofNullable(personQuery.getEndtime()).isPresent()) {
                    endtime1 = simpleDateFormat.parse(personQuery.getEndtime());
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }

            //创建时间
//            QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
            if (Optional.ofNullable(personQuery.getBegintime()).isPresent()) {
                personQueryWrapper.between("birth_time", begintime1, endtime1);
            }
            //关键字
            if (Optional.ofNullable(personQuery.getKeyWord()).isPresent()) {
                personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.like("name", personQuery.getKeyWord()).or().like("tel", personQuery.getKeyWord())
                        .or().like("id_number", personQuery.getKeyWord()));
            }
            //性别
            if (Optional.ofNullable(personQuery.getGender()).isPresent()) {
                personQueryWrapper.eq("gender", personQuery.getGender());
            }
            //民族
            if (Optional.ofNullable(personQuery.getNation()).isPresent()) {
                personQueryWrapper.eq("nation", personQuery.getNation());
            }
            //户籍编号
            if (Optional.ofNullable(personQuery.getHouseNumber()).isPresent()) {
                personQueryWrapper.eq("house_number", personQuery.getHouseNumber());
            }

            Queue<String> queue = new ArrayDeque<>();
            if (personQuery.getInformation() != null) {
                if (!personQuery.getInformation().isEmpty()) {
                    for (String s : personQuery.getInformation()) {
                        if (s.equals("租户")) {
                            queue.add("tent_inset");
                        }
                        if (s.equals("老年人")) {
                            queue.add("oldman_inset");
                        }
                        if (s.equals("残疾人")) {
                            queue.add("defor_inset");
                        }
                        if (s.equals("党员")) {
                            queue.add("part_inset");
                        }
                        if (s.equals("低保")) {
                            queue.add("under_inset");
                        }
                        if (s.equals("优抚")) {
                            queue.add("care_inset");
                        }
                    }
                }
                personQueryWrapper = PackSql(personQueryWrapper, queue, personQuery.getInformation().size());
            }

            //居住地
            if (Optional.ofNullable(personQuery.getLiveAddress()).isPresent()) {
                if (personQuery.getLiveAddress().equals("0")) {
                    personQueryWrapper.eq("inside2", false);
//                区域外
                    if (Optional.ofNullable(personQuery.getOut2Province()).isPresent()) {
                        personQueryWrapper.eq("out2_province", personQuery.getOut2Province());
                    }
                    if (Optional.ofNullable(personQuery.getOut2City()).isPresent()) {
                        personQueryWrapper.eq("out2_city", personQuery.getOut2City());
                    }
                    if (Optional.ofNullable(personQuery.getOut2FullAddress()).isPresent()) {
                        personQueryWrapper.eq("out2_full_address", personQuery.getOut2FullAddress());
                    }
                } else if (personQuery.getLiveAddress().equals("1")) {
//                区域内
                    personQueryWrapper.eq("inside2", true);
                    QueryWrapper<Residence> residenceQueryWrapper = new QueryWrapper<>();
                    residenceQueryWrapper.eq("enabled", true);
                    if (Optional.ofNullable(personQuery.getResidenceAddress()).isPresent()) {
                        residenceQueryWrapper.eq("category", personQuery.getResidenceAddress());
                    }
                    if (Optional.ofNullable(personQuery.getLiveCommunity()).isPresent()) {
                        residenceQueryWrapper.eq("community_id", personQuery.getLiveCommunity());
                    }
                    if (Optional.ofNullable(personQuery.getLivePlot()).isPresent()) {
                        residenceQueryWrapper.eq("plot_id", personQuery.getLivePlot());
                    }
                    if (Optional.ofNullable(personQuery.getDetailedAddress()).isPresent()) {
//                        List<String> list = JSONObject.parseArray(personQuery.getDetailedAddress(), String.class);
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int i = 0; i < personQuery.getDetailedAddress().size(); i++) {
                            if (i == 0) {
                                stringBuilder.append(personQuery.getDetailedAddress().get(0)).append("/");
                                continue;
                            }
                            stringBuilder.append(personQuery.getDetailedAddress().get(i));
                        }
                        residenceQueryWrapper.eq("address", stringBuilder.toString());
                    }
                    if (Optional.ofNullable(personQuery.getHouseNum()).isPresent()) {

                        residenceQueryWrapper.eq("house_number", personQuery.getHouseNum());
                    }
                    List<Residence> residences = residenceDao.selectList(residenceQueryWrapper);
//                    if (!residences.isEmpty()) {
//                        stringList.clear();
//                    }
                    List<String> list = new ArrayList<>();
                    for (Residence residence : residences) {
//                        boolean contains = stringList.contains(residence.getId());
//                        if (!contains){
//                            stringList.add(residence.getId());
//                        }
                        list.add(residence.getId());
                    }
                    if (!list.isEmpty()) {
                        personQueryWrapper.in("abode_id", list);
                    } else {
                        List<String> list1 = new ArrayList<>();
                        list1.add("哈哈哈");
                        personQueryWrapper.in("abode_id", list1);
                    }
                }
            }
            //户籍地
            if (Optional.ofNullable(personQuery.getLiveAddress2()).isPresent()) {
                if (personQuery.getLiveAddress2().equals("0")) {
                    personQueryWrapper.eq("inside1", false);
//                区域外
                    if (Optional.ofNullable(personQuery.getOut1Province()).isPresent()) {
                        personQueryWrapper.eq("out1_province", personQuery.getOut1Province());
                    }
                    if (Optional.ofNullable(personQuery.getOut1City()).isPresent()) {
                        personQueryWrapper.eq("out1_city", personQuery.getOut1City());
                    }
                    if (Optional.ofNullable(personQuery.getOut1FullAddress()).isPresent()) {
                        personQueryWrapper.eq("out1_full_address", personQuery.getOut1FullAddress());
                    }
                } else if (personQuery.getLiveAddress2().equals("1")) {
//                区域内
                    personQueryWrapper.eq("inside1", true);
                    QueryWrapper<Residence> residenceQueryWrapper = new QueryWrapper<>();
                    residenceQueryWrapper.eq("enabled", true);
                    if (Optional.ofNullable(personQuery.getResidenceAddress2()).isPresent()) {
                        residenceQueryWrapper.eq("category", personQuery.getResidenceAddress2());
                    }
                    if (Optional.ofNullable(personQuery.getLiveCommunity2()).isPresent()) {
                        residenceQueryWrapper.eq("community_id", personQuery.getLiveCommunity2());
                    }
                    if (Optional.ofNullable(personQuery.getLivePlot2()).isPresent()) {
                        residenceQueryWrapper.eq("plot_id", personQuery.getLivePlot2());
                    }
                    if (Optional.ofNullable(personQuery.getDetailedAddress2()).isPresent()) {
//                        List<String> list = JSONObject.parseArray(personQuery.getDetailedAddress(), String.class);
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int i = 0; i < personQuery.getDetailedAddress2().size(); i++) {
                            if (i == 0) {
                                stringBuilder.append(personQuery.getDetailedAddress2().get(0) + "/");
                                continue;
                            }
                            stringBuilder.append(personQuery.getDetailedAddress2().get(i));
                        }
                        residenceQueryWrapper.eq("address", stringBuilder.toString());
                    }
                    if (Optional.ofNullable(personQuery.getHouseNum2()).isPresent()) {

                        residenceQueryWrapper.eq("house_number", personQuery.getHouseNum2());
                    }
                    List<Residence> residences = residenceDao.selectList(residenceQueryWrapper);
                    List<String> list = new ArrayList<>();
                    for (Residence residence : residences) {
//                        if (!residences.isEmpty()){
//                            stringList2.clear();
//                        }
                        list.add(residence.getId());
//                        boolean contains = stringList2.contains(residence.getId());
//                        if (!contains){
//                            stringList2.add(residence.getId());
//                        }
                    }
                    if (!list.isEmpty()) {
                        personQueryWrapper.in("place_id", list);
                    } else {
                        List<String> list1 = new ArrayList<>();
                        list1.add("哈哈哈");
                        personQueryWrapper.in("place_id", list1);
                    }
                }
            }
        }


//        地区和权限筛选
        if (stringList.size() > 0) {
            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().isNull("abode_id").or().eq("abode_id", ""));
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id", "").or().isNull("place_id"));
//            personQueryWrapper.eq("place_id","");
        } else if ("street:admin".equals(roleKey)) {

        } else {
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","")
//                    .or().eq("place_id",""));
            personQueryWrapper.eq("abode_id", "");
//            personQueryWrapper.isNull("abode_id");
        }

//        if (stringList2.size()>0) {
//            personQueryWrapper.in("place_id", stringList2);
//        }else if ("street:admin".equals(roleKey)){
//
//        }else {
//            stringList2.add("哈哈哈");
//            personQueryWrapper.in("place_id", stringList2);
//        }


        Page<Person> page1 = new Page<>(page, limit);
        personQueryWrapper.eq("enabled", true);
        Page<Person> personPage = personDao.selectPage(page1, personQueryWrapper);


        //处理结果集
        List<JSONObject> jsonObjects = new ArrayList<>();
        for (Person person : personPage.getRecords()) {
            boolean a = false;
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(person));

            List<String> list = new ArrayList<>();
            StringBuilder stringBuilder = new StringBuilder();
            if (person.getOldmanInset().equals("true")) {
                list.add("老年人");
            }

            if (person.getDeforInset().equals("true")) {
                list.add("残疾人");
            }
            if (person.getUnderInset().equals("true")) {
                list.add("低保");
            }

            if (person.getCareInset().equals("true")) {
                list.add("优抚");
            }

            if (person.getPartInset().equals("true")) {
                list.add("党员");
            }

            if (person.getTentInset().equals("true")) {
                list.add("租户");
            }
            int i = 0;
            for (String s : list) {
                if (i != 0) {
                    stringBuilder.append(",");
                }
                stringBuilder.append(s);
                i++;
            }

            jsonObject.put("information3", stringBuilder.toString());

            if (person.getInside2()) {
                Residence residence = residenceDao.selectById(person.getAbodeId());
                if (Optional.ofNullable(residence).isPresent()) {

                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
                    jsonObject.put("abode_address", s);
                }
            } else {
                StringBuilder builder = new StringBuilder();
                if(StringUtils.hasText(person.getOut2Province())){
                    builder.append(person.getOut2Province());
                }
                if(StringUtils.hasText(person.getOut2City())){
                    builder.append(person.getOut2City());
                }
                if(StringUtils.hasText(person.getOut2FullAddress())){
                    builder.append(person.getOut2FullAddress());
                }
                jsonObject.put("abode_address", builder.toString());
            }
            if (person.getInside1()) {
                Residence residence = residenceDao.selectById(person.getPlaceId());
                if (Optional.ofNullable(residence).isPresent()) {
                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
                    jsonObject.put("place_address", s);
                }
            } else {
                StringBuilder builder = new StringBuilder();
                if(StringUtils.hasText(person.getOut1Province())){
                    builder.append(person.getOut1Province());
                }
                if(StringUtils.hasText(person.getOut1City())){
                    builder.append(person.getOut1City());
                }
                if(StringUtils.hasText(person.getOut1FullAddress())){
                    builder.append(person.getOut1FullAddress());
                }
                jsonObject.put("place_address", builder.toString());
            }
            jsonObjects.add(jsonObject);
        }

        Page<JSONObject> page2 = new Page<>();
        page2.setPages(personPage.getPages());
        page2.setMaxLimit(personPage.getMaxLimit());
        page2.setRecords(jsonObjects);
        page2.setSize(personPage.getSize());
        page2.setCurrent(personPage.getCurrent());
        page2.setTotal(personPage.getTotal());
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(page2).build();
    }

    @Override
    public ResponseResult findById(String id) {
        Person person = personDao.selectById(id);
        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(person));
        if (person.getInside2()) {
            Residence residence = residenceDao.selectById(person.getAbodeId());
            JSONObject jsonObject2 = JSONObject.parseObject(JSONObject.toJSONString(residence));
            SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
            jsonObject2.put("plot_name", sysPlot.getName());
            SysCommunity sysCommunity = syscommunityDao.selectById(residence.getCommunityId());
            jsonObject2.put("com_name", sysCommunity.getName());

            SysPlot sysPlot2 = sysPlotDao.selectById(residence.getPlotId());
            String address = residence.getAddress();
            List<String> addrArray = new LinkedList<>();
            if (residence.getCategory().equals("平房/别墅")) {
                String bungalowVilla = sysPlot2.getBungalowVilla();
                PlotMessage plotMessage = JSON.parseObject(bungalowVilla, PlotMessage.class);
                List<BungalowVilla> bungalowVillas = plotMessage.getBungalowVillas();
                for (BungalowVilla villa : bungalowVillas) {
                    if (villa.getArea().equals(address)) {
                        addrArray.add(villa.getId());
                        break;
                    }
                }
            }
            String[] strings = address.split("/");
            String buildingUnit = sysPlot2.getBuildingUnit();
            PlotMessage plotMessage = JSON.parseObject(buildingUnit, PlotMessage.class);
            List<Building> buildings = plotMessage.getBuildings();
            for (Building building : buildings) {
                if (building.getStoriedBuilding().equals(strings[0])) {
                    addrArray.add(building.getId());
                    List<Unit> units = building.getUnits();
                    for (Unit unit : units) {
                        if (unit.getUnit().equals(strings[1])) {
                            addrArray.add(unit.getId());
                            break;
                        }
                    }
                }
            }
            jsonObject2.put("addrArray", addrArray);


            jsonObject.put("abode", jsonObject2);
        }
        if (person.getInside1() && Optional.ofNullable(person.getPlaceId()).isPresent() && !StringUtil.isNullOrEmpty(person.getPlaceId())) {
            Residence residence = residenceDao.selectById(person.getPlaceId());
            JSONObject jsonObject3 = JSONObject.parseObject(JSONObject.toJSONString(residence));
            SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
            jsonObject3.put("plot_name", sysPlot.getName());
            SysCommunity sysCommunity = syscommunityDao.selectById(residence.getCommunityId());
            jsonObject3.put("com_name", sysCommunity.getName());
            if (residence.getCategory().equals("楼房")) {
                jsonObject3.put("addrArray", residence.getAddress().split("/"));
            }

            SysPlot sysPlot2 = sysPlotDao.selectById(residence.getPlotId());
            String address = residence.getAddress();
            List<String> addrArray = new LinkedList<>();
            if (residence.getCategory().equals("平房/别墅")) {
                String bungalowVilla = sysPlot2.getBungalowVilla();
                PlotMessage plotMessage = JSON.parseObject(bungalowVilla, PlotMessage.class);
                List<BungalowVilla> bungalowVillas = plotMessage.getBungalowVillas();
                for (BungalowVilla villa : bungalowVillas) {
                    if (villa.getArea().equals(address)) {
                        addrArray.add(villa.getId());
                        break;
                    }
                }
            }
            String[] strings = address.split("/");
            String buildingUnit = sysPlot2.getBuildingUnit();
            PlotMessage plotMessage = JSON.parseObject(buildingUnit, PlotMessage.class);
            List<Building> buildings = plotMessage.getBuildings();
            for (Building building : buildings) {
                if (building.getStoriedBuilding().equals(strings[0])) {
                    addrArray.add(building.getId());
                    List<Unit> units = building.getUnits();
                    for (Unit unit : units) {
                        if (unit.getUnit().equals(strings[1])) {
                            addrArray.add(unit.getId());
                            break;
                        }
                    }
                }
            }
            jsonObject3.put("addrArray", addrArray);

            jsonObject.put("place", jsonObject3);
        }

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (Optional.ofNullable(person.getMarriedTime()).isPresent()) {
            String format = simpleDateFormat.format(person.getMarriedTime());
            jsonObject.remove("marriedTime");
            String s = format.split(" ")[0];
            jsonObject.put("marriedTime", s);
        }


        if (Optional.ofNullable(person.getBirthTime()).isPresent()) {
            String format2 = simpleDateFormat.format(person.getBirthTime());
            jsonObject.remove("birthTime");
            String s2 = format2.split(" ")[0];
            jsonObject.put("birthTime", s2);
        }

//        家庭信息
        QueryWrapper<Person> personQueryWrapper = new QueryWrapper<>();
        personQueryWrapper.eq("enabled", true);
        if (Optional.ofNullable(person.getPlaceId()).isPresent() && !StringUtil.isNullOrEmpty(person.getPlaceId())){
            personQueryWrapper.eq("place_id", person.getPlaceId());
        }else {
            personQueryWrapper.eq("place_id", "未知");
        }

        personQueryWrapper.eq("inside1", true);
        List<Person> list = personDao.selectList(personQueryWrapper);
        List<JSONObject> list1 = new ArrayList<>();
        for (Person person1 : list) {
            JSONObject jsonObject1 = JSONObject.parseObject(JSONObject.toJSONString(person1));
            if (person1.getInside1()) {
                Residence residence = residenceDao.selectById(person1.getPlaceId());
                if (Optional.ofNullable(residence).isPresent()) {
                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
                    jsonObject1.put("place_address", s);
                }
            } else {
                String s = person1.getOut1Province() + person1.getOut1City() + person1.getOut1FullAddress();
                jsonObject1.put("place_address", s);
            }
            list1.add(jsonObject1);
        }
        jsonObject.put("kasokuInfo", list1);
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
    }

    @Override
    public ResponseResult export(JSONObject jsonObject) {
        List<String> stringList = new ArrayList<>();
        List<Person> list = new ArrayList<>();
        if (Optional.ofNullable(jsonObject.getJSONArray("ids")).isPresent()) {
            JSONArray ids = jsonObject.getJSONArray("ids");
            List<String> list1 = ids.toJavaList(String.class);
            for (String s : list1) {
                Person person = personDao.selectById(s);
                list.add(person);
            }
        } else {
            //权限筛选
            //获取当前登陆人的信息
            User user = (User) ShiroUtils.getSubject().getPrincipal();
            LambdaQueryWrapper<SysUserRole> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
            lambdaQueryWrapper5.eq(SysUserRole::getUserId, user.getId());
            SysUserRole sysUserRole = sysUserRoleDao.selectOne(lambdaQueryWrapper5);
            String roleKey = sysRoleDao.findByRoles(sysUserRole.getRoleId());
            if (!"street:admin".equals(roleKey)) {
                List<String> commnityIds = sysUserCommunityDao.commnityIds(user.getId());
                if (Objects.isNull(commnityIds) || commnityIds.size() <= 0) {
                    return ResponseResult.builder().message("当前用户还没有任何社区权限").build();
                }
                List<SysCommunity> communities = sysCommunityDao.findByCommunity(commnityIds);
                List<String> ids = new ArrayList<>();
                for (SysCommunity community : communities) {
                    ids.add(community.getId());
                }
                QueryWrapper<Residence> queryWrapper = new QueryWrapper<>();
                List<Residence> residences = new ArrayList<>();
                if (!commnityIds.isEmpty()) {
                    queryWrapper.in("community_id", commnityIds);
                    queryWrapper.eq("enabled", true);
                    residences = residenceDao.selectList(queryWrapper);
                } else {

                }

                for (Residence residence : residences) {
                    stringList.add(residence.getId());
                }
            }
            QueryWrapper<Person> queryWrapper = new QueryWrapper<>();

            PersonQuery personQuery = jsonObject.toJavaObject(PersonQuery.class);

//        复杂查询
            if (Optional.ofNullable(personQuery).isPresent()) {
                Date begintime1 = null;
                Date endtime1 = null;
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    if (Optional.ofNullable(personQuery.getBegintime()).isPresent()) {
                        begintime1 = simpleDateFormat.parse(personQuery.getBegintime());
                    }
                    if (Optional.ofNullable(personQuery.getEndtime()).isPresent()) {
                        endtime1 = simpleDateFormat.parse(personQuery.getEndtime());
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }

                //创建时间
//            QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
                if (Optional.ofNullable(personQuery.getBegintime()).isPresent()) {
                    queryWrapper.between("birth_time", begintime1, endtime1);
                }
                //关键字
                if (Optional.ofNullable(personQuery.getKeyWord()).isPresent()) {
                    queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.like("name", personQuery.getKeyWord()).or().like("tel", personQuery.getKeyWord())
                            .or().like("id_number", personQuery.getKeyWord()));
                }
                //性别
                if (Optional.ofNullable(personQuery.getGender()).isPresent()) {
                    queryWrapper.eq("gender", personQuery.getGender());
                }
                //民族
                if (Optional.ofNullable(personQuery.getNation()).isPresent()) {
                    queryWrapper.eq("nation", personQuery.getNation());
                }
                //户籍编号
                if (Optional.ofNullable(personQuery.getHouseNumber()).isPresent()) {
                    queryWrapper.eq("house_number", personQuery.getHouseNumber());
                }

                Queue<String> queue = new ArrayDeque<>();
                if (personQuery.getInformation() != null) {
                    if (!personQuery.getInformation().isEmpty()) {
                        for (String s : personQuery.getInformation()) {
                            if (s.equals("租户")) {
                                queue.add("tent_inset");
                            }
                            if (s.equals("老年人")) {
                                queue.add("oldman_inset");
                            }
                            if (s.equals("残疾人")) {
                                queue.add("defor_inset");
                            }
                            if (s.equals("党员")) {
                                queue.add("part_inset");
                            }
                            if (s.equals("低保")) {
                                queue.add("under_inset");
                            }
                            if (s.equals("优抚")) {
                                queue.add("care_inset");
                            }
                        }
                    }
                    queryWrapper = PackSql(queryWrapper, queue, personQuery.getInformation().size());
                }

                //居住地
                if (Optional.ofNullable(personQuery.getLiveAddress()).isPresent()) {
                    if (personQuery.getLiveAddress().equals("0")) {
                        queryWrapper.eq("inside2", false);
//                区域外
                        if (Optional.ofNullable(personQuery.getOut2Province()).isPresent()) {
                            queryWrapper.eq("out2_province", personQuery.getOut2Province());
                        }
                        if (Optional.ofNullable(personQuery.getOut2City()).isPresent()) {
                            queryWrapper.eq("out2_city", personQuery.getOut2City());
                        }
                        if (Optional.ofNullable(personQuery.getOut2FullAddress()).isPresent()) {
                            queryWrapper.eq("out2_full_address", personQuery.getOut2FullAddress());
                        }
                    } else if (personQuery.getLiveAddress().equals("1")) {
//                区域内
                        queryWrapper.eq("inside2", true);
                        QueryWrapper<Residence> residenceQueryWrapper = new QueryWrapper<>();
                        residenceQueryWrapper.eq("enabled", true);
                        if (Optional.ofNullable(personQuery.getResidenceAddress()).isPresent()) {
                            residenceQueryWrapper.eq("category", personQuery.getResidenceAddress());
                        }
                        if (Optional.ofNullable(personQuery.getLiveCommunity()).isPresent()) {
                            residenceQueryWrapper.eq("community_id", personQuery.getLiveCommunity());
                        }
                        if (Optional.ofNullable(personQuery.getLivePlot()).isPresent()) {
                            residenceQueryWrapper.eq("plot_id", personQuery.getLivePlot());
                        }
                        if (Optional.ofNullable(personQuery.getDetailedAddress()).isPresent()) {
//                        List<String> list = JSONObject.parseArray(personQuery.getDetailedAddress(), String.class);
                            StringBuilder stringBuilder = new StringBuilder();
                            for (int i = 0; i < personQuery.getDetailedAddress().size(); i++) {
                                if (i == 0) {
                                    stringBuilder.append(personQuery.getDetailedAddress().get(0) + "/");
                                    continue;
                                }
                                stringBuilder.append(personQuery.getDetailedAddress().get(i));
                            }
                            residenceQueryWrapper.eq("address", stringBuilder.toString());
                        }
                        if (Optional.ofNullable(personQuery.getHouseNum()).isPresent()) {

                            residenceQueryWrapper.eq("house_number", personQuery.getHouseNum());
                        }
                        List<Residence> residences = residenceDao.selectList(residenceQueryWrapper);
//                    if (!residences.isEmpty()) {
//                        stringList.clear();
//                    }
                        List<String> list2 = new ArrayList<>();
                        for (Residence residence : residences) {
//                        boolean contains = stringList.contains(residence.getId());
//                        if (!contains){
//                            stringList.add(residence.getId());
//                        }
                            list2.add(residence.getId());
                        }
                        if (!list2.isEmpty()) {
                            queryWrapper.in("abode_id", list2);
                        } else {
                            List<String> list1 = new ArrayList<>();
                            list1.add("哈哈哈");
                            queryWrapper.in("abode_id", list1);
                        }
                    }
                }
                //户籍地
                if (Optional.ofNullable(personQuery.getLiveAddress2()).isPresent()) {
                    if (personQuery.getLiveAddress2().equals("0")) {
                        queryWrapper.eq("inside1", false);
//                区域外
                        if (Optional.ofNullable(personQuery.getOut1Province()).isPresent()) {
                            queryWrapper.eq("out1_province", personQuery.getOut1Province());
                        }
                        if (Optional.ofNullable(personQuery.getOut1City()).isPresent()) {
                            queryWrapper.eq("out1_city", personQuery.getOut1City());
                        }
                        if (Optional.ofNullable(personQuery.getOut1FullAddress()).isPresent()) {
                            queryWrapper.eq("out1_full_address", personQuery.getOut1FullAddress());
                        }
                    } else if (personQuery.getLiveAddress2().equals("1")) {
//                区域内
                        queryWrapper.eq("inside1", true);
                        QueryWrapper<Residence> residenceQueryWrapper = new QueryWrapper<>();
                        residenceQueryWrapper.eq("enabled", true);
                        if (Optional.ofNullable(personQuery.getResidenceAddress2()).isPresent()) {
                            residenceQueryWrapper.eq("category", personQuery.getResidenceAddress2());
                        }
                        if (Optional.ofNullable(personQuery.getLiveCommunity2()).isPresent()) {
                            residenceQueryWrapper.eq("community_id", personQuery.getLiveCommunity2());
                        }
                        if (Optional.ofNullable(personQuery.getLivePlot2()).isPresent()) {
                            residenceQueryWrapper.eq("plot_id", personQuery.getLivePlot2());
                        }
                        if (Optional.ofNullable(personQuery.getDetailedAddress2()).isPresent()) {
//                        List<String> list = JSONObject.parseArray(personQuery.getDetailedAddress(), String.class);
                            StringBuilder stringBuilder = new StringBuilder();
                            for (int i = 0; i < personQuery.getDetailedAddress2().size(); i++) {
                                if (i == 0) {
                                    stringBuilder.append(personQuery.getDetailedAddress2().get(0) + "/");
                                    continue;
                                }
                                stringBuilder.append(personQuery.getDetailedAddress2().get(i));
                            }
                            residenceQueryWrapper.eq("address", stringBuilder.toString());
                        }
                        if (Optional.ofNullable(personQuery.getHouseNum2()).isPresent()) {

                            residenceQueryWrapper.eq("house_number", personQuery.getHouseNum2());
                        }
                        List<Residence> residences = residenceDao.selectList(residenceQueryWrapper);
                        List<String> list2 = new ArrayList<>();
                        for (Residence residence : residences) {
//                        if (!residences.isEmpty()){
//                            stringList2.clear();
//                        }
                            list2.add(residence.getId());
//                        boolean contains = stringList2.contains(residence.getId());
//                        if (!contains){
//                            stringList2.add(residence.getId());
//                        }
                        }
                        if (!list2.isEmpty()) {
                            queryWrapper.in("place_id", list2);
                        } else {
                            List<String> list1 = new ArrayList<>();
                            list1.add("哈哈哈");
                            queryWrapper.in("place_id", list1);
                        }
                    }
                }
            }
//        地区和权限筛选
//            if (stringList.size() > 0) {
//                queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().eq("abode_id", ""));
//                queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id", ""));
//
////                queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().in("place_id",stringList));
//            } else if ("street:admin".equals(roleKey)) {
//
//            } else {
//                queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id", "").or().eq("place_id", ""));
////            personQueryWrapper.isNull("abode_id");
//            }
            if (stringList.size() > 0) {
                queryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("abode_id", stringList).or().isNull("abode_id").or().eq("abode_id", ""));
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.in("place_id", stringList).or().eq("place_id", "").or().isNull("place_id"));
//            personQueryWrapper.eq("place_id","");
            } else if ("street:admin".equals(roleKey)) {
            } else {
//            personQueryWrapper.and(personQueryWrapper1 -> personQueryWrapper1.eq("abode_id","")
//                    .or().eq("place_id",""));
                queryWrapper.eq("abode_id", "");
//            personQueryWrapper.isNull("abode_id");
            }
            queryWrapper.eq("enabled", true);
            list = personDao.selectList(queryWrapper);
        }
        HSSFWorkbook workbook = new HSSFWorkbook();
        String filename = "社区个人导出信息.xlsx";
        HSSFSheet sheet = workbook.createSheet("导出信息");
        String[] headers = new String[]{"姓名", "性别", "年龄", "民族", "身份证号", "手机号码", "居住地址", "户籍编号", "户籍地址", "综合信息"};
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setBorderTop(BorderStyle.THIN);
        cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
        cellStyle.setBorderRight(BorderStyle.THIN);
        cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
//        第一行类别
        int i;
        for (i = 0; i < headers.length; ++i) {
            HSSFCell cell = row.createCell(i);
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);
            cell.setCellStyle(cellStyle);
        }
//        内容
        for (int j = 0; j < list.size(); j++) {
            HSSFRow row1 = sheet.createRow(j + 1);

            if (list.get(j).getName().equals("321")) {
                System.out.println("1");
            }

//            姓名
            Cell cell0 = row1.createCell(0);
            cell0.setCellValue(list.get(j).getName());
            cell0.setCellStyle(cellStyle);
//            性别
            Cell cell1 = row1.createCell(1);
            cell1.setCellValue(list.get(j).getGender());
            cell1.setCellStyle(cellStyle);
//            年龄
            Cell cell2 = row1.createCell(2);
            cell2.setCellValue(list.get(j).getAge());
            cell2.setCellStyle(cellStyle);
//            民族
            Cell cell4 = row1.createCell(3);
            cell4.setCellValue(list.get(j).getNation());
            cell4.setCellStyle(cellStyle);
//            身份证号
            Cell cell5 = row1.createCell(4);
            cell5.setCellValue(list.get(j).getIdNumber());
            cell5.setCellStyle(cellStyle);
//            手机号码
            Cell cell6 = row1.createCell(5);
            cell6.setCellValue(list.get(j).getTel());
            cell6.setCellStyle(cellStyle);
//            居住地址
            Cell cell7 = row1.createCell(6);
            if (list.get(j).getInside2()) {
                Residence residence = residenceDao.selectById(list.get(j).getAbodeId());
                if (Optional.ofNullable(residence).isPresent()) {
                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
                    cell7.setCellValue(s);
                }
            } else {
                String s = list.get(j).getOut2Province() + list.get(j).getOut2City() + list.get(j).getOut2FullAddress();
                if (s.equals("nullnullnull")) {
                    s = " ";
                }else if(s.indexOf("null") == -1){
                    String[] strings = s.split("null");
                    s = "";
                    for (int i1 = 0; i1 < strings.length; i1++) {
                        s = s+strings[i1];
                    }
                }
                cell7.setCellValue(s);
            }
            cell7.setCellStyle(cellStyle);
//            户籍编号
            Cell cell8 = row1.createCell(7);
            cell8.setCellValue(list.get(j).getHouseNumber());
            cell8.setCellStyle(cellStyle);
//            户籍地址
            Cell cell9 = row1.createCell(8);
            if (list.get(j).getInside1()) {
                Residence residence = residenceDao.selectById(list.get(j).getPlaceId());
                if (Optional.ofNullable(residence).isPresent()) {
                    SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                    String s = sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber();
                    cell9.setCellValue(s);
                }
            } else {
                String s = list.get(j).getOut1Province() + list.get(j).getOut1City() + list.get(j).getOut1FullAddress();
                if (s.equals("nullnullnull")) {
                    s = " ";
                }
                cell9.setCellValue(s);
            }
            cell9.setCellStyle(cellStyle);
//            综合信息
            List<String> list2 = new ArrayList<>();
            StringBuilder stringBuilder = new StringBuilder();
//            StringBuilder stringBuilder = new StringBuilder();
            if (list.get(j).getOldmanInset().equals("true")) {
                list2.add("老年人");
            }
            if (list.get(j).getDeforInset().equals("true")) {
                list2.add("残疾人");
            }
            if (list.get(j).getUnderInset().equals("true")) {
                list2.add("低保");
            }
            if (list.get(j).getCareInset().equals("true")) {
                list2.add("优抚");
            }
            if (list.get(j).getPartInset().equals("true")) {
                list2.add("党员");
            }
            if (list.get(j).getTentInset().equals("true")) {
                list2.add("租户");
            }

            int i2 = 0;
            for (String s : list2) {
                if (i2 != 0) {
                    stringBuilder.append(",");
                }
                stringBuilder.append(s);
                i++;
            }

//            jsonObject.put("information3",stringBuilder.toString());
            Cell cell10 = row1.createCell(9);
            cell10.setCellValue(stringBuilder.toString());
            cell10.setCellStyle(cellStyle);
        }

//        File sourceFile = new File(dir+"LS/");
//        String s = null;


        OutputStream os2 = null;
        String outPath2 = dir;
        try {
//            s = ZipUtils.fileToZip(sourceFile);
            File outFilePath2 = new File(outPath2);
            if (!outFilePath2.exists()) {
                outFilePath2.mkdirs();
            }
            outPath2 = outPath2 + "/" + new Date().getTime() + filename;
            os2 = new FileOutputStream(outPath2);
            workbook.write(os2);
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(outPath2).build();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (os2 != null) {
                    os2.close();
                }
                workbook.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return ResponseResult.builder().code(ResultCode.SYSTEM_ERROR.getCode()).message(ResultCode.SYSTEM_ERROR.getMessage()).build();
    }

    @Override
    public ResponseResult findByCard(String card) {
        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("enabled", true);
        queryWrapper.eq("id_number", card);
        Person person = personDao.selectOne(queryWrapper);
        String s = " ";
        JSONObject jsonObject = new JSONObject();
        if (Optional.ofNullable(person).isPresent()) {
            if (person.getInside2()) {
                Residence residence = residenceDao.selectById(person.getAbodeId());
                SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
                SysPlot sysPlot = sysplotDao.selectById(residence.getPlotId());
                s = "身份证号为\"" + card + "\"已经关联居住地址为\"" + sysCommunity.getName() + sysPlot.getName() + residence.getAddress() + residence.getHouseNumber() + "\",是否变更此人员的居住地址!";
            } else {
                s = "身份证号为\"" + card + "\"已经关联居住地址为\"" + person.getOut2Province() + person.getOut2City() + person.getOut2FullAddress() + "\",是否变更此人员的居住地址";
            }
            jsonObject.put("id", person.getId());
            jsonObject.put("mes", s);
            return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
        }
        jsonObject.put("id", null);
//        jsonObject.put("mes",s);
        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
//        return null;
    }

    /**
     * 动态拼接sql
     *
     * @param queryWrapper
     * @param queue
     * @param size
     * @return
     */
    private QueryWrapper<Person> PackSql(QueryWrapper<Person> queryWrapper, Queue<String> queue, int size) {
        switch (size) {
            case 0:
                return queryWrapper;
            case 1: {
                queryWrapper.and(personQueryWrapper -> personQueryWrapper.eq(queue.poll(), "true"));
                return queryWrapper;
            }
            case 2: {
                queryWrapper.and(personQueryWrapper -> personQueryWrapper.eq(queue.poll(), "true")).eq(queue.poll(), "true");
                return queryWrapper;
            }
            case 3: {
                queryWrapper.and(personQueryWrapper -> personQueryWrapper.eq(queue.poll(), "true")).eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true");
                return queryWrapper;
            }
            case 4: {
                queryWrapper.and(personQueryWrapper -> personQueryWrapper.eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true"));
                return queryWrapper;
            }
            case 5: {
                queryWrapper.and(personQueryWrapper -> personQueryWrapper.eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true"));
                return queryWrapper;
            }
            case 6: {
                queryWrapper.and(personQueryWrapper -> personQueryWrapper.eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true").eq(queue.poll(), "true")).eq(queue.poll(), "true");
                return queryWrapper;
            }
        }
        return null;
    }

    private String chageLog(Person old, Person newone) {
        Residence residence = residenceDao.selectById(old.getAbodeId());
        Residence residence1 = residenceDao.selectById(newone.getAbodeId());
        SysCommunity sysCommunity = sysCommunityDao.selectById(residence.getCommunityId());
        SysCommunity sysCommunity1 = sysCommunityDao.selectById(residence1.getCommunityId());
        String s = "由\"" + sysCommunity.getName() + "\"转入\"" + sysCommunity1.getName() + "\"";
        return s;
//        else if (!old.getInside2() && newone.getInside2()){//由区域外转为区域内
//
//        }else if (old.getInside2() && !newone.getInside2()){//由区域内转为区域外
//
//        }
    }

    private boolean isChageLog(Person old, Person newone) {
        if (old.getInside2() && newone.getInside2()) { //由区域内转为区域内
            Residence residence = residenceDao.selectById(old.getAbodeId());
            Residence residence1 = residenceDao.selectById(newone.getAbodeId());
            if (Optional.ofNullable(residence).isPresent() && Optional.ofNullable(residence1).isPresent() ) {
                if (!residence.getCommunityId().equals(residence1.getCommunityId())) {
                    return true;
                }
            }
            return false;
        }
//        else if (!old.getInside2() && newone.getInside2()){//由区域外转为区域内
//            return true;
//        }else if (old.getInside2() && !newone.getInside2()){//由区域内转为区域外
//            return true;
//        }
        return false;
    }

    private Person mark(Person person) {
        JSONObject jsonObject = JSONObject.parseObject(person.getOldman());
        boolean enable = jsonObject.getBoolean("enable");
        if (enable) {
            person.setOldmanInset("true");
        } else {
            person.setOldmanInset("false");
        }

        jsonObject = JSONObject.parseObject(person.getCareMan());
        enable = jsonObject.getBoolean("enable");
        if (enable) {
            person.setCareInset("true");
        } else {
            person.setCareInset("false");
        }

        jsonObject = JSONObject.parseObject(person.getPartMan());
        enable = jsonObject.getBoolean("enable");
        if (enable) {
            person.setPartInset("true");
        } else {
            person.setPartInset("false");
        }

        jsonObject = JSONObject.parseObject(person.getUnderProtect());
        enable = jsonObject.getBoolean("enable");
        if (enable) {
            person.setUnderInset("true");
        } else {
            person.setUnderInset("false");
        }

        jsonObject = JSONObject.parseObject(person.getDeformedMan());
        enable = jsonObject.getBoolean("enable");
        if (enable) {
            person.setDeforInset("true");
        } else {
            person.setDeforInset("false");
        }

        jsonObject = JSONObject.parseObject(person.getTenant());
        enable = jsonObject.getBoolean("enable");
        if (enable) {
            person.setTentInset("true");
            person.setLivehold("租赁");
        } else {
            person.setTentInset("false");
        }

        return person;
    }

    public String excelWrite(List<ExcelOrder> list,String str){
        //创建一个目录
        File dir2 = new File(dir);
        if(!dir2.exists()){
            //目录如果不存在就创建一个
            dir2.mkdirs();
        }
        //1、创建一个文件对象
//        String string = UUID.randomUUID().toString();
//        File excelFile = new File(str+".xlsx");
//        //2、判断文件是否存在，不存在则创建一个Excel文件
//        if (!excelFile.exists()) {
//            try {
//                excelFile.createNewFile();//创建一个新的文件
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
        String excelFileName = dir + str + ".xlsx";
        //3、指定需要那个class去写。然后写到第一个sheet，名字为模版，然后文件流会自动关闭
        EasyExcel.write(excelFileName, ExcelOrder.class).sheet("人员").doWrite(list);
        return excelFileName;
    }

//
//    @Override
//    public ResponseResult selectPage(Integer limit, Integer page) {
//        Page<SysRole> page1 = new Page<>(page-1,limit);
//
//        QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("enabled",true);
////        queryWrapper.like("name",condition);
//
//        List<JSONObject> list = new ArrayList<>();
//
//        Page<SysRole> userPage = sysRoleDao.selectPage(page1, queryWrapper);
//        for (SysRole sysRole : userPage.getRecords()){
//            QueryWrapper<SysRoleMenu> queryWrapper1 = new QueryWrapper();
//            queryWrapper1.eq("role_id",sysRole.getId());
//            List<SysRoleMenu> sysRoleMenus = sysRoleMenuDao.selectList(queryWrapper1);
//
//            JSONObject jsonObject = new JSONObject();
//            jsonObject.put("id",sysRole.getId());
//            jsonObject.put("name",sysRole.getName());
//            jsonObject.put("number",sysRoleMenus.size());
//            list.add(jsonObject);
//        }
//
//        Page<JSONObject> page2 = new Page<>();
//        page2.setPages(userPage.getPages());
//        page2.setMaxLimit(userPage.getMaxLimit());
//        page2.setRecords(list);
//        page2.setSize(userPage.getSize());
//        page2.setCurrent(userPage.getCurrent());
//        page2.setTotal(userPage.getTotal());
//        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(page2).build();
//    }
//
//    @Override
//    public ResponseResult findById(String s) {
//        SysRole sysRole = sysRoleDao.selectById(s);
//        JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(sysRole));
//        QueryWrapper<SysRoleMenu> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("role_id",s);
//        List<SysRoleMenu> sysRoleMenus = sysRoleMenuDao.selectList(queryWrapper);
//        jsonObject.put("menus",sysRoleMenus);
//        return ResponseResult.builder().code(ResultCode.NORMAL.getCode()).message(ResultCode.NORMAL.getMessage()).data(jsonObject).build();
//    }

    /**
     * 将json中日期类型转为毫秒值存储
     */
    public Person conversionDate(Person person) {
        if (!Objects.isNull(person)) {
            String oldman = person.getOldman();//老年人
            String deformedMan = person.getDeformedMan();//残疾人
            String underProtect = person.getUnderProtect();//低保户
            String careMan = person.getCareMan();// 优抚
            String partMan = person.getPartMan();//党员
            String tenant = person.getTenant();//租户
            if (org.springframework.util.StringUtils.hasText(oldman)) {
                OldMsgDto oldMsgDto = JSON.parseObject(oldman, OldMsgDto.class);
                String oldJsonString = JSON.toJSONString(oldMsgDto);
                person.setOldman(oldJsonString);
            }
            if (org.springframework.util.StringUtils.hasText(deformedMan)) {
                DisabilityMsgDto disabilityMsgDto = JSON.parseObject(deformedMan, DisabilityMsgDto.class);
                String disabilityJsonString = JSON.toJSONString(disabilityMsgDto);
                person.setDeformedMan(disabilityJsonString);
            }
            if (org.springframework.util.StringUtils.hasText(underProtect)) {
                SubsistenceMsgDto subsistenceMsgDto = JSON.parseObject(underProtect, SubsistenceMsgDto.class);
                String subsistenceJsonString = JSON.toJSONString(subsistenceMsgDto);
                person.setUnderProtect(subsistenceJsonString);
            }
            if (org.springframework.util.StringUtils.hasText(careMan)) {
                SpecialMsgDto specialMsgDto = JSON.parseObject(careMan, SpecialMsgDto.class);
                String specialJsonString = JSON.toJSONString(specialMsgDto);
                person.setCareMan(specialJsonString);
            }
            if (org.springframework.util.StringUtils.hasText(partMan)) {
                MemberMsgDto memberMsgDto = JSON.parseObject(partMan, MemberMsgDto.class);
                String memberJsonString = JSON.toJSONString(memberMsgDto);
                person.setPartMan(memberJsonString);
            }
            if (org.springframework.util.StringUtils.hasText(tenant)) {
                TenantMsgDto tenantMsgDto = JSON.parseObject(tenant, TenantMsgDto.class);
                String tenantJsonString = JSON.toJSONString(tenantMsgDto);
                person.setTenant(tenantJsonString);
            }
            return person;
        }
        return null;
    }

    /**
     * 修改个人信息记录修改的内容
     */
    public StringBuilder logPerson(Person oldPerson, Person newPerson) {
        StringBuilder builder = new StringBuilder();

        //户籍地
        if (StringUtils.hasText(oldPerson.getPlace())) {
            if (StringUtils.hasText(newPerson.getPlace())) {
                if (!oldPerson.getPlace().equals(newPerson.getPlace())) {
                    builder.append("户籍地修改前:").append(oldPerson.getPlace()).append(",修改后:").append(newPerson.getPlace()).append("。");
                }
            } else {
                builder.append("户籍地修改前:").append(oldPerson.getPlace()).append(",修改后:无").append("。");
            }
        } else {
            if (StringUtils.hasText(newPerson.getPlace())) {
                builder.append("户籍地修改前:无").append(",修改后:").append(newPerson.getPlace()).append("。");
            }
        }

        //户籍地址
        if (StringUtils.hasText(oldPerson.getPlace())) {//修改前 户籍地不为空
            if(oldPerson.getPlace().equals("辖区内")){//修改前 户籍地在辖区内
                if(StringUtils.hasText(oldPerson.getPlaceId())){//修改前 户籍辖区内且有户籍id
                    Residence oldResidence = residenceDao.selectById(oldPerson.getPlaceId());
                    SysCommunity sysCommunity = sysCommunityDao.selectById(oldResidence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(oldResidence.getPlotId());
                    if(StringUtils.hasText(newPerson.getPlace())){//修改后 户籍地不为空
                        if(newPerson.getPlace().equals("辖区内")){//修改后 户籍地在辖区内
                            if(StringUtils.hasText(newPerson.getPlaceId())){//修改后 户籍id不为null
                                if(!oldPerson.getPlaceId().equals(newPerson.getPlaceId())){
                                    Residence newResidence = residenceDao.selectById(newPerson.getPlaceId());
                                    SysCommunity sysCommunity1 = sysCommunityDao.selectById(newResidence.getCommunityId());
                                    SysPlot sysPlot1 = sysplotDao.selectById(newResidence.getPlotId());
                                    builder.append("户籍地址修改前:")
                                            .append(oldResidence.getCategory())
                                            .append(sysCommunity.getName())
                                            .append(sysPlot.getName())
                                            .append(oldResidence.getAddress())
                                            .append(oldResidence.getHouseNumber())
                                            .append(",修改后:")
                                            .append(newResidence.getCategory())
                                            .append(sysCommunity1.getName())
                                            .append(sysPlot1.getName())
                                            .append(newResidence.getAddress())
                                            .append(newResidence.getHouseNumber())
                                            .append("。");
                                }
                            }else{//修改后 户籍id为null
                                builder.append("户籍地址修改前:")
                                        .append(oldResidence.getCategory())
                                        .append(sysCommunity.getName())
                                        .append(sysPlot.getName())
                                        .append(oldResidence.getAddress())
                                        .append(oldResidence.getHouseNumber())
                                        .append(",修改后:")
                                        .append("无")
                                        .append("。");
                            }
                        }else{//修改后 户籍地变成辖区外
                            if(StringUtils.hasText(newPerson.getPlaceId())){
                                builder.append("户籍地址修改前:")
                                        .append(oldResidence.getCategory())
                                        .append(sysCommunity.getName())
                                        .append(sysPlot.getName())
                                        .append(oldResidence.getAddress())
                                        .append(oldResidence.getHouseNumber())
                                        .append(",修改后:");
                                        if(StringUtils.hasText(newPerson.getOut1Province())){
                                            builder.append(newPerson.getOut1Province());
                                        }
                                        if(StringUtils.hasText(newPerson.getOut1City())){
                                            builder.append(newPerson.getOut1City());
                                        }
                                        if(StringUtils.hasText(newPerson.getOut1FullAddress())){
                                            builder.append(newPerson.getOut1FullAddress());
                                        }
                                        builder.append("。");
                            }
                        }
                    }else{//修改后  户籍地为空
                        builder.append("户籍地址修改前:")
                                .append(oldResidence.getCategory())
                                .append(sysCommunity.getName())
                                .append(sysPlot.getName())
                                .append(oldResidence.getAddress())
                                .append(oldResidence.getHouseNumber())
                                .append(",修改后:无")
                                .append("。");
                    }
                }else {//修改前 户籍辖区内没有有户籍id
                    builder.append("户籍地址修改前:无");
                    if(StringUtils.hasText(newPerson.getPlace())){//修改后 户籍地不为空
                        if(newPerson.getPlace().equals("辖区内")){//修改后 户籍地不为空,且为辖区内
                            if(StringUtils.hasText(newPerson.getPlaceId())){
                                Residence newResidence = residenceDao.selectById(newPerson.getPlaceId());
                                SysCommunity sysCommunity1 = sysCommunityDao.selectById(newResidence.getCommunityId());
                                SysPlot sysPlot1 = sysplotDao.selectById(newResidence.getPlotId());
                                builder.append("户籍地址修改前:无")
                                        .append(",修改后:")
                                        .append(newResidence.getCategory())
                                        .append(sysCommunity1.getName())
                                        .append(sysPlot1.getName())
                                        .append(newResidence.getAddress())
                                        .append(newResidence.getHouseNumber())
                                        .append("。");
                            }
                        }else {//修改后 户籍地不为空,且为辖区外
                            builder.append("户籍地址修改前:无")
                                    .append(",修改后:");
                            if(StringUtils.hasText(newPerson.getOut1Province())){
                                builder.append(newPerson.getOut1Province());
                            }
                            if(StringUtils.hasText(newPerson.getOut1City())){
                                builder.append(newPerson.getOut1City());
                            }
                            if(StringUtils.hasText(newPerson.getOut1FullAddress())){
                                builder.append(newPerson.getOut1FullAddress());
                            }
                            builder.append("。");
                        }
                    }
                }
            }else{//修改前 户籍辖外
                if(StringUtils.hasText(newPerson.getPlace())){//修改后 户籍地不为null
                    if(newPerson.getPlace().equals("辖区内")){//修改后 户籍地为辖区内
                        if(StringUtils.hasText(newPerson.getPlaceId())){//修改后 户籍地为辖区内且placeid不为null
                            Residence newResidence = residenceDao.selectById(newPerson.getPlaceId());
                            SysCommunity sysCommunity1 = sysCommunityDao.selectById(newResidence.getCommunityId());
                            SysPlot sysPlot1 = sysplotDao.selectById(newResidence.getPlotId());
                            builder.append("户籍地址修改前:");
                            if(StringUtils.hasText(oldPerson.getOut1Province())){
                                builder.append(oldPerson.getOut1Province());
                            }
                            if(StringUtils.hasText(oldPerson.getOut1City())){
                                builder.append(oldPerson.getOut1City());
                            }
                            if(StringUtils.hasText(oldPerson.getOut1FullAddress())){
                                builder.append(oldPerson.getOut1FullAddress());
                            }
                            builder.append(",修改后:")
                                    .append(newResidence.getCategory())
                                    .append(sysCommunity1.getName())
                                    .append(sysPlot1.getName())
                                    .append(newResidence.getAddress())
                                    .append(newResidence.getHouseNumber())
                                    .append("。");
                        }else {
                            builder.append("户籍地址修改前:");
                            if(StringUtils.hasText(oldPerson.getOut1Province())){
                                builder.append(oldPerson.getOut1Province());
                            }
                            if(StringUtils.hasText(oldPerson.getOut1City())){
                                builder.append(oldPerson.getOut1City());
                            }
                            if(StringUtils.hasText(oldPerson.getOut1FullAddress())){
                                builder.append(oldPerson.getOut1FullAddress());
                            }
                            builder.append(",修改后:无");
                        }
                    }else {//修改后 户籍地为辖区外
                        builder.append("户籍地址修改前:");
                        if(StringUtils.hasText(oldPerson.getOut1Province())){
                            builder.append(oldPerson.getOut1Province());
                        }
                        if(StringUtils.hasText(oldPerson.getOut1City())){
                            builder.append(oldPerson.getOut1City());
                        }
                        if(StringUtils.hasText(oldPerson.getOut1FullAddress())){
                            builder.append(oldPerson.getOut1FullAddress());
                        }
                        builder.append(",修改后:");
                        if(StringUtils.hasText(newPerson.getOut1Province())){
                            builder.append(newPerson.getOut1Province());
                        }
                        if(StringUtils.hasText(newPerson.getOut1City())){
                            builder.append(newPerson.getOut1City());
                        }
                        if(StringUtils.hasText(newPerson.getOut1FullAddress())){
                            builder.append(newPerson.getOut1FullAddress());
                        }
                        builder.append("。");
                    }
                }
            }
        }

        //户主或与户主关系
        if (StringUtils.hasText(oldPerson.getRelationship())) {
            if (StringUtils.hasText(newPerson.getRelationship())) {
                if (!oldPerson.getRelationship().equals(newPerson.getRelationship())) {
                    builder.append("户主或与户主关系修改前:")
                            .append(oldPerson.getRelationship())
                            .append(",修改后:")
                            .append(newPerson.getRelationship())
                            .append("。");
                }
            } else {
                builder.append("户主或与户主关系修改前:")
                        .append(oldPerson.getRelationship())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newPerson.getRelationship())) {
                builder.append("户主或与户主关系修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getRelationship())
                        .append("。");
            }
        }

        //户主性质
        if (StringUtils.hasText(oldPerson.getHousehold())) {
            if (StringUtils.hasText(newPerson.getHousehold())) {
                if (!oldPerson.getHousehold().equals(newPerson.getHousehold())) {
                    builder.append("户主性质修改前:")
                            .append(oldPerson.getHousehold())
                            .append(",修改后:")
                            .append(newPerson.getHousehold())
                            .append("。");
                }
            } else {
                builder.append("户主性质修改前:")
                        .append(oldPerson.getHousehold())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getHousehold())) {
                builder.append("户主性质修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getHousehold())
                        .append("。");
            }
        }

        //原籍类型
        if (StringUtils.hasText(oldPerson.getOriginType())) {
            if (StringUtils.hasText(newPerson.getOriginType())) {
                if (!oldPerson.getOriginType().equals(newPerson.getOriginType())) {
                    builder.append("原籍类型修改前:")
                            .append(oldPerson.getOriginType())
                            .append(",修改后:")
                            .append(newPerson.getOriginType())
                            .append("。");
                }
            } else {
                builder.append("原籍类型修改前:")
                        .append(oldPerson.getOriginType())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newPerson.getOriginType())) {
                builder.append("原籍类型修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getOriginType())
                        .append("。");
            }
        }

        //文化程度
        if (StringUtils.hasText(oldPerson.getStandard())) {
            if (StringUtils.hasText(newPerson.getStandard())) {
                if (!oldPerson.getStandard().equals(newPerson.getStandard())) {
                    builder.append("文化程度修改前:")
                            .append(oldPerson.getStandard())
                            .append(",修改后:")
                            .append(newPerson.getStandard())
                            .append("。");
                }
            } else {

                builder.append("文化程度修改前:")
                        .append(oldPerson.getStandard())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getStandard())) {
                builder.append("文化程度修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getStandard())
                        .append("。");
            }
        }

        //婚姻状况
        if (StringUtils.hasText(oldPerson.getMaritalStatus())) {
            if (StringUtils.hasText(newPerson.getMaritalStatus())) {
                if (!oldPerson.getMaritalStatus().equals(newPerson.getMaritalStatus())) {
                    builder.append("婚姻状况修改前:")
                            .append(oldPerson.getMaritalStatus())
                            .append(",修改后:")
                            .append(newPerson.getMaritalStatus())
                            .append("。");
                }
            } else {

                builder.append("婚姻状况修改前:")
                        .append(oldPerson.getMaritalStatus())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getMaritalStatus())) {
                builder.append("婚姻状况修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getMaritalStatus())
                        .append("。");
            }
        }

        //户籍编号
        if (StringUtils.hasText(oldPerson.getHouseNumber())) {
            if (StringUtils.hasText(newPerson.getHouseNumber())) {
                if (!oldPerson.getHouseNumber().equals(newPerson.getHouseNumber())) {
                    builder.append("户籍编号修改前:")
                            .append(oldPerson.getHouseNumber())
                            .append(",修改后:")
                            .append(newPerson.getHouseNumber())
                            .append("。");
                }
            } else {

                builder.append("户籍编号修改前:")
                        .append(oldPerson.getHouseNumber())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getHouseNumber())) {
                builder.append("户籍编号修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getHouseNumber())
                        .append("。");
            }
        }

        //户籍派出所
        if (StringUtils.hasText(oldPerson.getPoliceStation())) {
            if (StringUtils.hasText(newPerson.getPoliceStation())) {
                if (!oldPerson.getPoliceStation().equals(newPerson.getPoliceStation())) {
                    builder.append("户籍派出所修改前:")
                            .append(oldPerson.getPoliceStation())
                            .append(",修改后:")
                            .append(newPerson.getPoliceStation())
                            .append("。");
                }
            } else {

                builder.append("户籍派出所修改前:")
                        .append(oldPerson.getPoliceStation())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getPoliceStation())) {
                builder.append("户籍派出所修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getPoliceStation())
                        .append("。");
            }
        }

        //居住地
        if (StringUtils.hasText(oldPerson.getAbode())) {
            if (StringUtils.hasText(newPerson.getAbode())) {
                if (!oldPerson.getAbode().equals(newPerson.getAbode())) {
                    builder.append("居住地修改前:").append(oldPerson.getAbode()).append(",修改后:").append(newPerson.getAbode()).append("。");
                }
            } else {
                builder.append("居住地修改前:").append(oldPerson.getAbode()).append(",修改后:无").append("。");
            }
        } else {
            if (StringUtils.hasText(newPerson.getAbode())) {
                builder.append("居住地修改前:无").append(",修改后:").append(newPerson.getAbode()).append("。");
            }
        }

        //居住地址
        if (StringUtils.hasText(oldPerson.getAbode())) {//修改前 户籍地不为空
            if(oldPerson.getAbode().equals("辖区内")){//修改前 户籍地在辖区内
                if(StringUtils.hasText(oldPerson.getAbodeId())){//修改前 户籍辖区内且有户籍id
                    Residence oldResidence = residenceDao.selectById(oldPerson.getAbodeId());
                    SysCommunity sysCommunity = sysCommunityDao.selectById(oldResidence.getCommunityId());
                    SysPlot sysPlot = sysplotDao.selectById(oldResidence.getPlotId());
                    if(StringUtils.hasText(newPerson.getAbode())){//修改后 户籍地不为空
                        if(newPerson.getAbode().equals("辖区内")){//修改后 户籍地在辖区内
                            if(StringUtils.hasText(newPerson.getAbodeId())){//修改后 户籍id不为null
                                if(!oldPerson.getAbodeId().equals(newPerson.getAbodeId())){
                                    Residence newResidence = residenceDao.selectById(newPerson.getAbodeId());
                                    SysCommunity sysCommunity1 = sysCommunityDao.selectById(newResidence.getCommunityId());
                                    SysPlot sysPlot1 = sysplotDao.selectById(newResidence.getPlotId());
                                    builder.append("居住地址修改前:")
                                            .append(oldResidence.getCategory())
                                            .append(sysCommunity.getName())
                                            .append(sysPlot.getName())
                                            .append(oldResidence.getAddress())
                                            .append(oldResidence.getHouseNumber())
                                            .append(",修改后:")
                                            .append(newResidence.getCategory())
                                            .append(sysCommunity1.getName())
                                            .append(sysPlot1.getName())
                                            .append(newResidence.getAddress())
                                            .append(newResidence.getHouseNumber())
                                            .append("。");
                                }
                            }else{//修改后 户籍id为null
                                builder.append("居住地址修改前:")
                                        .append(oldResidence.getCategory())
                                        .append(sysCommunity.getName())
                                        .append(sysPlot.getName())
                                        .append(oldResidence.getAddress())
                                        .append(oldResidence.getHouseNumber())
                                        .append(",修改后:")
                                        .append("无")
                                        .append("。");
                            }
                        }else{//修改后 户籍地变成辖区外
                            if(StringUtils.hasText(newPerson.getAbodeId())){
                                builder.append("居住地址修改前:")
                                        .append(oldResidence.getCategory())
                                        .append(sysCommunity.getName())
                                        .append(sysPlot.getName())
                                        .append(oldResidence.getAddress())
                                        .append(oldResidence.getHouseNumber())
                                        .append(",修改后:");
                                if(StringUtils.hasText(newPerson.getOut2Province())){
                                    builder.append(newPerson.getOut2Province());
                                }
                                if(StringUtils.hasText(newPerson.getOut2City())){
                                    builder.append(newPerson.getOut2City());
                                }
                                if(StringUtils.hasText(newPerson.getOut2FullAddress())){
                                    builder.append(newPerson.getOut2FullAddress());
                                }
                                builder.append("。");
                            }
                        }
                    }else{//修改后  户籍地为空
                        builder.append("居住地址修改前:")
                                .append(oldResidence.getCategory())
                                .append(sysCommunity.getName())
                                .append(sysPlot.getName())
                                .append(oldResidence.getAddress())
                                .append(oldResidence.getHouseNumber())
                                .append(",修改后:无")
                                .append("。");
                    }
                }else {//修改前 户籍辖区内没有有户籍id
                    builder.append("居住地址修改前:无");
                    if(StringUtils.hasText(newPerson.getAbode())){//修改后 户籍地不为空
                        if(newPerson.getAbode().equals("辖区内")){//修改后 户籍地不为空,且为辖区内
                            if(StringUtils.hasText(newPerson.getAbodeId())){
                                Residence newResidence = residenceDao.selectById(newPerson.getAbodeId());
                                SysCommunity sysCommunity1 = sysCommunityDao.selectById(newResidence.getCommunityId());
                                SysPlot sysPlot1 = sysplotDao.selectById(newResidence.getPlotId());
                                        builder.append(",修改后:")
                                        .append(newResidence.getCategory())
                                        .append(sysCommunity1.getName())
                                        .append(sysPlot1.getName())
                                        .append(newResidence.getAddress())
                                        .append(newResidence.getHouseNumber())
                                        .append("。");
                            }
                        }else {//修改后 户籍地不为空,且为辖区外
                            builder.append(",修改后:");
                            if(StringUtils.hasText(newPerson.getOut2Province())){
                                builder.append(newPerson.getOut2Province());
                            }
                            if(StringUtils.hasText(newPerson.getOut2City())){
                                builder.append(newPerson.getOut2City());
                            }
                            if(StringUtils.hasText(newPerson.getOut2FullAddress())){
                                builder.append(newPerson.getOut2FullAddress());
                            }
                            builder.append("。");
                        }
                    }
                }
            }else{//修改前 户籍辖外
                if(StringUtils.hasText(newPerson.getAbode())){//修改后 户籍地不为null
                    if(newPerson.getAbode().equals("辖区内")){//修改后 户籍地为辖区内
                        if(StringUtils.hasText(newPerson.getAbodeId())){//修改后 户籍地为辖区内且placeid不为null
                            Residence newResidence = residenceDao.selectById(newPerson.getAbodeId());
                            SysCommunity sysCommunity1 = sysCommunityDao.selectById(newResidence.getCommunityId());
                            SysPlot sysPlot1 = sysplotDao.selectById(newResidence.getPlotId());
                            builder.append("居住地址修改前:");
                            if(StringUtils.hasText(oldPerson.getOut2Province())){
                                builder.append(oldPerson.getOut2Province());
                            }
                            if(StringUtils.hasText(oldPerson.getOut2City())){
                                builder.append(oldPerson.getOut2City());
                            }
                            if(StringUtils.hasText(oldPerson.getOut2FullAddress())){
                                builder.append(oldPerson.getOut2FullAddress());
                            }
                            builder.append(",修改后:")
                                    .append(newResidence.getCategory())
                                    .append(sysCommunity1.getName())
                                    .append(sysPlot1.getName())
                                    .append(newResidence.getAddress())
                                    .append(newResidence.getHouseNumber())
                                    .append("。");
                        }else {
                            builder.append("居住地址修改前:");
                            if(StringUtils.hasText(oldPerson.getOut2Province())){
                                builder.append(oldPerson.getOut1Province());
                            }
                            if(StringUtils.hasText(oldPerson.getOut2City())){
                                builder.append(oldPerson.getOut2City());
                            }
                            if(StringUtils.hasText(oldPerson.getOut2FullAddress())){
                                builder.append(oldPerson.getOut2FullAddress());
                            }
                            builder.append(",修改后:无");
                        }
                    }else {//修改后 户籍地为辖区外
                        builder.append("居住地址修改前:");
                        if(StringUtils.hasText(oldPerson.getOut2Province())){
                            builder.append(oldPerson.getOut2Province());
                        }
                        if(StringUtils.hasText(oldPerson.getOut2City())){
                            builder.append(oldPerson.getOut2City());
                        }
                        if(StringUtils.hasText(oldPerson.getOut2FullAddress())){
                            builder.append(oldPerson.getOut2FullAddress());
                        }
                        builder.append(",修改后:");
                        if(StringUtils.hasText(newPerson.getOut2Province())){
                            builder.append(newPerson.getOut2Province());
                        }
                        if(StringUtils.hasText(newPerson.getOut2City())){
                            builder.append(newPerson.getOut2City());
                        }
                        if(StringUtils.hasText(newPerson.getOut2FullAddress())){
                            builder.append(newPerson.getOut2FullAddress());
                        }
                        builder.append("。");
                    }
                }
            }
        }

        //出生地
        if (StringUtils.hasText(oldPerson.getBirthPlace())) {
            if (StringUtils.hasText(newPerson.getBirthPlace())) {
                if (!oldPerson.getBirthPlace().equals(newPerson.getBirthPlace())) {
                    builder.append("出生地修改前:")
                            .append(oldPerson.getBirthPlace())
                            .append(",修改后:")
                            .append(newPerson.getBirthPlace())
                            .append("。");
                }
            } else {
                if (StringUtils.hasText(newPerson.getBirthPlace())) {
                    builder.append("出生地修改前:")
                            .append(oldPerson.getBirthPlace())
                            .append(",修改后:无")
                            .append("。");
                }
            }
        } else {
            if (StringUtils.hasText(newPerson.getBirthPlace())) {
                builder.append("出生地修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getBirthPlace())
                        .append("。");
            }
        }

        //流动人口
        if (StringUtils.hasText(oldPerson.getMigrant())) {
            if (StringUtils.hasText(newPerson.getMigrant())) {
                if (!oldPerson.getMigrant().equals(newPerson.getMigrant())) {
                    builder.append("流动人口修改前:")
                            .append(oldPerson.getMigrant())
                            .append(",修改后:")
                            .append(newPerson.getMigrant())
                            .append("。");
                }
            } else {

                builder.append("流动人口修改前:")
                        .append(oldPerson.getMigrant())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getMigrant())) {
                builder.append("流动人口修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getMigrant())
                        .append("。");
            }
        }

        //社会保障
        if (StringUtils.hasText(oldPerson.getSocialSecurity())) {
            if (StringUtils.hasText(newPerson.getSocialSecurity())) {
                if (!oldPerson.getSocialSecurity().equals(newPerson.getSocialSecurity())) {
                    builder.append("社会保障修改前:")
                            .append(oldPerson.getSocialSecurity())
                            .append(",修改后:")
                            .append(newPerson.getSocialSecurity())
                            .append("。");
                }
            } else {

                builder.append("社会保障修改前:")
                        .append(oldPerson.getSocialSecurity())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getSocialSecurity())) {
                builder.append("社会保障修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getSocialSecurity())
                        .append("。");
            }
        }

        //结婚日期
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        if (oldPerson.getMarriedTime() != null) {
            if (newPerson.getMarriedTime() != null) {
                if (!format.format(oldPerson.getMarriedTime()).equals(format.format(newPerson.getMarriedTime()))) {
                    builder.append("结婚日期修改前:")
                            .append(format.format(oldPerson.getMarriedTime()))
                            .append(",修改后:")
                            .append(format.format(newPerson.getMarriedTime()))
                            .append("。");
                }
            } else {
                builder.append("结婚日期修改前:")
                        .append(format.format(oldPerson.getMarriedTime()))
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (newPerson.getMarriedTime() != null) {
                builder.append("结婚日期修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(format.format(newPerson.getMarriedTime()))
                        .append("。");
            }
        }

        //计生类别
        if (StringUtils.hasText(oldPerson.getFamilyPlan())) {
            if (StringUtils.hasText(newPerson.getFamilyPlan())) {
                if (!oldPerson.getFamilyPlan().equals(newPerson.getFamilyPlan())) {
                    builder.append("计生类别修改前:")
                            .append(oldPerson.getFamilyPlan())
                            .append(",修改后:")
                            .append(newPerson.getFamilyPlan())
                            .append("。");
                }
            } else {

                builder.append("计生类别修改前:")
                        .append(oldPerson.getFamilyPlan())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getFamilyPlan())) {
                builder.append("计生类别修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getFamilyPlan())
                        .append("。");
            }
        }

        //子女信息
        if (StringUtils.hasText(oldPerson.getSon())) {
            if (StringUtils.hasText(newPerson.getSon())) {
                if (!oldPerson.getSon().equals(newPerson.getSon())) {
                    builder.append("子女信息修改前:")
                            .append(oldPerson.getSon())
                            .append(",修改后:")
                            .append(newPerson.getSon())
                            .append("。");
                }
            } else {

                builder.append("子女信息修改前:")
                        .append(oldPerson.getSon())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getSon())) {
                builder.append("子女信息修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getSon())
                        .append("。");
            }
        }

        //工作类别
        if (StringUtils.hasText(oldPerson.getJobType())) {
            if (StringUtils.hasText(newPerson.getJobType())) {
                if (!oldPerson.getJobType().equals(newPerson.getJobType())) {
                    builder.append("工作类别修改前:")
                            .append(oldPerson.getJobType())
                            .append(",修改后:")
                            .append(newPerson.getJobType())
                            .append("。");
                }
            } else {

                builder.append("工作类别修改前:")
                        .append(oldPerson.getJobType())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getJobType())) {
                builder.append("工作类别修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getJobType())
                        .append("。");
            }
        }

        //工作单位
        if (StringUtils.hasText(oldPerson.getJobUnit())) {
            if (StringUtils.hasText(newPerson.getJobUnit())) {
                if (!oldPerson.getJobUnit().equals(newPerson.getJobUnit())) {
                    builder.append("工作单位修改前:")
                            .append(oldPerson.getJobUnit())
                            .append(",修改后:")
                            .append(newPerson.getJobUnit())
                            .append("。");
                }
            } else {
                builder.append("工作单位修改前:")
                        .append(oldPerson.getJobUnit())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getJobUnit())) {
                builder.append("工作单位修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getJobUnit())
                        .append("。");
            }
        }

        //健康状况
        if (StringUtils.hasText(oldPerson.getHealthState())) {
            if (StringUtils.hasText(newPerson.getHealthState())) {
                if (!oldPerson.getHealthState().equals(newPerson.getHealthState())) {
                    builder.append("健康状况修改前:")
                            .append(oldPerson.getHealthState())
                            .append(",修改后:")
                            .append(newPerson.getHealthState())
                            .append("。");
                }
            } else {
                builder.append("健康状况修改前:")
                        .append(oldPerson.getHealthState())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getHealthState())) {
                builder.append("健康状况修改前:无")
                        .append(",修改后:")
                        .append(newPerson.getHealthState())
                        .append("。");
            }
        }

        //特殊人群
        if (StringUtils.hasText(oldPerson.getCrowd())) {
            if (StringUtils.hasText(newPerson.getCrowd())) {
                if (!oldPerson.getCrowd().equals(newPerson.getCrowd())) {
                    builder.append("特殊人群修改前:")
                            .append(oldPerson.getCrowd())
                            .append(",修改后:")
                            .append(newPerson.getCrowd())
                            .append("。");
                }
            } else {
                builder.append("特殊人群修改前:")
                        .append(oldPerson.getCrowd())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getCrowd())) {
                builder.append("特殊人群修改前:无")
                        .append(",修改后:")
                        .append(newPerson.getCrowd())
                        .append("。");
            }
        }

        //其他备注
        if (StringUtils.hasText(oldPerson.getRemark())) {
            if (StringUtils.hasText(newPerson.getRemark())) {
                if (!oldPerson.getRemark().equals(newPerson.getRemark())) {
                    builder.append("其他备注修改前:")
                            .append(oldPerson.getRemark())
                            .append(",修改后:")
                            .append(newPerson.getRemark())
                            .append("。");
                }
            } else {
                builder.append("其他备注修改前:")
                        .append(oldPerson.getRemark())
                        .append(",修改后:无")
                        .append("。");

            }
        } else {
            if (StringUtils.hasText(newPerson.getRemark())) {
                builder.append("其他备注修改前:")
                        .append("无")
                        .append(",修改后:")
                        .append(newPerson.getRemark())
                        .append("。");
            }
        }

        //老年人信息
        String oldman = oldPerson.getOldman();
        OldMsgDto oldMsgDto = JSON.parseObject(oldman, OldMsgDto.class);
        String newman = newPerson.getOldman();
        OldMsgDto newMsgDto = JSON.parseObject(newman, OldMsgDto.class);
        builder.append("老年人信息:{");
        //老年人信息-生活能力
        if (StringUtils.hasText(oldMsgDto.getSurvivalSkills())) {
            if (StringUtils.hasText(newMsgDto.getSurvivalSkills())) {
                if (!oldMsgDto.getSurvivalSkills().equals(newMsgDto.getSurvivalSkills())) {
                    builder.append("生活能力修改前:")
                            .append(oldMsgDto.getSurvivalSkills())
                            .append(",修改后:")
                            .append(newMsgDto.getSurvivalSkills())
                            .append("。");
                }
            } else {
                builder.append("生活能力修改前:")
                        .append(oldMsgDto.getSurvivalSkills())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getSurvivalSkills())) {
                builder.append("生活能力修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getSurvivalSkills())
                        .append("。");
            }
        }
        //老年人信息-居住状况
        if (StringUtils.hasText(oldMsgDto.getLivingStatus())) {
            if (StringUtils.hasText(newMsgDto.getLivingStatus())) {
                if (!oldMsgDto.getLivingStatus().equals(newMsgDto.getLivingStatus())) {
                    builder.append("居住状况修改前:")
                            .append(oldMsgDto.getLivingStatus())
                            .append(",修改后:")
                            .append(newMsgDto.getLivingStatus())
                            .append("。");
                }
            } else {
                builder.append("居住状况修改前:")
                        .append(oldMsgDto.getLivingStatus())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getLivingStatus())) {
                builder.append("居住状况修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getLivingStatus())
                        .append("。");
            }
        }
        //老年人信息-特长
        if (StringUtils.hasText(oldMsgDto.getSpecialty())) {
            if (StringUtils.hasText(newMsgDto.getSpecialty())) {
                if (!oldMsgDto.getSpecialty().equals(newMsgDto.getSpecialty())) {
                    builder.append("特长修改前:")
                            .append(oldMsgDto.getSpecialty())
                            .append(",修改后:")
                            .append(newMsgDto.getSpecialty())
                            .append("。");
                }
            } else {
                builder.append("特长修改前:")
                        .append(oldMsgDto.getSpecialty())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getSpecialty())) {
                builder.append("特长修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getSpecialty())
                        .append("。");
            }
        }
        //老年人信息-经济来源
        if (StringUtils.hasText(oldMsgDto.getEconomicSource())) {
            if (StringUtils.hasText(newMsgDto.getEconomicSource())) {
                if (!oldMsgDto.getEconomicSource().equals(newMsgDto.getEconomicSource())) {
                    builder.append("经济来源修改前:")
                            .append(oldMsgDto.getEconomicSource())
                            .append(",修改后:")
                            .append(newMsgDto.getEconomicSource())
                            .append("。");
                }
            } else {
                builder.append("经济来源修改前:")
                        .append(oldMsgDto.getEconomicSource())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getEconomicSource())) {
                builder.append("经济来源修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getEconomicSource())
                        .append("。");
            }
        }
        //老年人信息-发挥作用
        if (StringUtils.hasText(oldMsgDto.getEffect())) {
            if (StringUtils.hasText(newMsgDto.getEffect())) {
                if (!oldMsgDto.getEffect().equals(newMsgDto.getEffect())) {
                    builder.append("发挥作用修改前:")
                            .append(oldMsgDto.getEffect())
                            .append(",修改后:")
                            .append(newMsgDto.getEffect())
                            .append("。");
                }
            } else {
                builder.append("发挥作用修改前:")
                        .append(oldMsgDto.getEffect())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getEffect())) {
                builder.append("发挥作用修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getEffect())
                        .append("。");
            }
        }
        //老年人信息-配偶情况
        if (StringUtils.hasText(oldMsgDto.getSpouse())) {
            if (StringUtils.hasText(newMsgDto.getSpouse())) {
                if (!oldMsgDto.getSpouse().equals(newMsgDto.getSpouse())) {
                    builder.append("配偶情况修改前:")
                            .append(oldMsgDto.getSpouse())
                            .append(",修改后:")
                            .append(newMsgDto.getSpouse())
                            .append("。");
                }
            } else {
                builder.append("配偶情况修改前:")
                        .append(oldMsgDto.getSpouse())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getSpouse())) {
                builder.append("配偶情况修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getSpouse())
                        .append("。");
            }
        }
        //老年人信息-领取优待证
        if (StringUtils.hasText(oldMsgDto.getPreferentialTreatmentCertificate())) {
            if (StringUtils.hasText(newMsgDto.getPreferentialTreatmentCertificate())) {
                if (!oldMsgDto.getPreferentialTreatmentCertificate().equals(newMsgDto.getPreferentialTreatmentCertificate())) {
                    builder.append("领取优待证修改前:")
                            .append(oldMsgDto.getPreferentialTreatmentCertificate())
                            .append(",修改后:")
                            .append(newMsgDto.getPreferentialTreatmentCertificate())
                            .append("。");
                }
            } else {
                builder.append("领取优待证修改前:")
                        .append(oldMsgDto.getPreferentialTreatmentCertificate())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getPreferentialTreatmentCertificate())) {
                builder.append("领取优待证修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getPreferentialTreatmentCertificate())
                        .append("。");
            }
        }
        //老年人信息-是否领取最高额外补贴
        if (!oldMsgDto.getHighSubsidy().equals(newMsgDto.getHighSubsidy())) {
            builder.append("是否领取高额补贴修改前:")
                    .append(oldMsgDto.getHighSubsidy() ? "是" : "否")
                    .append(",修改后:")
                    .append(newMsgDto.getHighSubsidy() ? "是" : "否")
                    .append("。");
        }
        //老年人信息-领证时间
        if (oldMsgDto.getCertificateTime() != null) {
            if (newMsgDto.getCertificateTime() != null) {
                if (!format.format(oldMsgDto.getCertificateTime()).equals(format.format(newMsgDto.getCertificateTime()))) {
                    builder.append("领证时间修改前:")
                            .append(format.format(oldMsgDto.getCertificateTime()))
                            .append(",修改后:")
                            .append(format.format(newMsgDto.getCertificateTime()))
                            .append("。");
                }
            } else {
                builder.append("领证时间修改前:")
                        .append(format.format(oldMsgDto.getCertificateTime()))
                        .append(",修改后:无")
                        .append("。");
            }

        } else {
            if (newMsgDto.getCertificateTime() != null) {
                if (StringUtils.hasText(format.format(newMsgDto.getCertificateTime()))) {
                    builder.append("领证时间修改前:无")
                            .append(",修改后:")
                            .append(format.format(newMsgDto.getCertificateTime()))
                            .append("。");
                }
            }
        }

        //老年人信息-优待证证号
        if (StringUtils.hasText(oldMsgDto.getCertificateNo())) {
            if (StringUtils.hasText(newMsgDto.getCertificateNo())) {
                if (!oldMsgDto.getCertificateNo().equals(newMsgDto.getCertificateNo())) {
                    builder.append("优待证证号修改前:")
                            .append(oldMsgDto.getCertificateNo())
                            .append(",修改后:")
                            .append(newMsgDto.getCertificateNo())
                            .append("。");
                }
            } else {
                builder.append("优待证证号修改前:")
                        .append(oldMsgDto.getCertificateNo())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getCertificateNo())) {
                builder.append("优待证证号修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getCertificateNo())
                        .append("。");
            }
        }
        //老年人信息-特殊情况
        if (Objects.nonNull(oldMsgDto.getSpecial()) && oldMsgDto.getSpecial().size() > 0) {
            if (Objects.nonNull(newMsgDto.getSpecial()) && newMsgDto.getSpecial().size() > 0) {
                if (!oldMsgDto.getCertificateNo().equals(newMsgDto.getCertificateNo())) {
                    builder.append("特殊情况修改前:")
                            .append(oldMsgDto.getSpecial())
                            .append(",修改后:")
                            .append(newMsgDto.getSpecial())
                            .append("。");
                }
            } else {
                builder.append("特殊情况修改前:")
                        .append(oldMsgDto.getSpecial())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (Objects.nonNull(newMsgDto.getSpecial()) && newMsgDto.getSpecial().size() > 0) {
                builder.append("特殊情况修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getSpecial())
                        .append("。");
            }
        }
        //老年人信息-其他备注
        if (StringUtils.hasText(oldMsgDto.getRemark())) {
            if (StringUtils.hasText(newMsgDto.getRemark())) {
                if (!oldMsgDto.getRemark().equals(newMsgDto.getRemark())) {
                    builder.append("其他备注修改前:")
                            .append(oldMsgDto.getRemark())
                            .append(",修改后:")
                            .append(newMsgDto.getRemark())
                            .append("。");
                }
            } else {
                builder.append("其他备注号修改前:")
                        .append(oldMsgDto.getRemark())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMsgDto.getRemark())) {
                builder.append("其他备注修改前:无")
                        .append(",修改后:")
                        .append(newMsgDto.getRemark())
                        .append("。");
            }
        }
        builder.append("}");

        //残疾人信息
        String oldDeformedMan = oldPerson.getDeformedMan();
        DisabilityMsgDto oldDisabilityMsgDto = JSON.parseObject(oldDeformedMan, DisabilityMsgDto.class);
        String newDeformedMan = newPerson.getDeformedMan();
        DisabilityMsgDto newDisabilityMsgDto = JSON.parseObject(newDeformedMan, DisabilityMsgDto.class);
        builder.append("残疾人信息:{");
        //残疾人信息-残疾证号
        if (StringUtils.hasText(oldDisabilityMsgDto.getDisabilityNo())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getDisabilityNo())) {
                if (!oldDisabilityMsgDto.getDisabilityNo().equals(newDisabilityMsgDto.getDisabilityNo())) {
                    builder.append("残疾证号修改前:")
                            .append(oldDisabilityMsgDto.getDisabilityNo())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getDisabilityNo())
                            .append("。");
                }
            } else {
                builder.append("残疾证号修改前:")
                        .append(oldDisabilityMsgDto.getDisabilityNo())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getDisabilityNo())) {
                builder.append("残疾证号修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getDisabilityNo())
                        .append("。");
            }
        }
        //残疾人信息-残疾等级
        if (StringUtils.hasText(oldDisabilityMsgDto.getDisabilityLevel())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getDisabilityLevel())) {
                if (!oldDisabilityMsgDto.getDisabilityLevel().equals(newDisabilityMsgDto.getDisabilityLevel())) {
                    builder.append("残疾等级修改前:")
                            .append(oldDisabilityMsgDto.getDisabilityLevel())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getDisabilityLevel())
                            .append("。");
                }
            } else {
                builder.append("残疾等级修改前:")
                        .append(oldDisabilityMsgDto.getDisabilityLevel())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getDisabilityLevel())) {
                builder.append("残疾等级修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getDisabilityLevel())
                        .append("。");
            }
        }
        //残疾人信息-残疾类别
        if (StringUtils.hasText(oldDisabilityMsgDto.getDisabilityType())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getDisabilityType())) {
                if (!oldDisabilityMsgDto.getDisabilityType().equals(newDisabilityMsgDto.getDisabilityType())) {
                    builder.append("残疾类别修改前:")
                            .append(oldDisabilityMsgDto.getDisabilityType())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getDisabilityType())
                            .append("。");
                }
            } else {
                builder.append("残疾类别修改前:")
                        .append(oldDisabilityMsgDto.getDisabilityType())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getDisabilityType())) {
                builder.append("残疾类别修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getDisabilityType())
                        .append("。");
            }
        }
        //残疾人信息-劳动能力
        if (StringUtils.hasText(oldDisabilityMsgDto.getLaborCapacity())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getLaborCapacity())) {
                if (!oldDisabilityMsgDto.getLaborCapacity().equals(newDisabilityMsgDto.getLaborCapacity())) {
                    builder.append("劳动能力修改前:")
                            .append(oldDisabilityMsgDto.getLaborCapacity())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getLaborCapacity())
                            .append("。");
                }
            } else {
                builder.append("劳动能力修改前:")
                        .append(oldDisabilityMsgDto.getLaborCapacity())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getLaborCapacity())) {
                builder.append("劳动能力修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getLaborCapacity())
                        .append("。");
            }
        }
        //残疾人信息-法定监护人
        if (StringUtils.hasText(oldDisabilityMsgDto.getLegalGuardian())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getLegalGuardian())) {
                if (!oldDisabilityMsgDto.getLegalGuardian().equals(newDisabilityMsgDto.getLegalGuardian())) {
                    builder.append("法定监护人修改前:")
                            .append(oldDisabilityMsgDto.getLegalGuardian())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getLegalGuardian())
                            .append("。");
                }
            } else {
                builder.append("法定监护人修改前:")
                        .append(oldDisabilityMsgDto.getLegalGuardian())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getLegalGuardian())) {
                builder.append("法定监护人修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getLegalGuardian())
                        .append("。");
            }
        }
        //残疾人信息-残疾需求
        if (StringUtils.hasText(oldDisabilityMsgDto.getDisabilityNeeds())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getDisabilityNeeds())) {
                if (!oldDisabilityMsgDto.getDisabilityNeeds().equals(newDisabilityMsgDto.getDisabilityNeeds())) {
                    builder.append("残疾需求修改前:")
                            .append(oldDisabilityMsgDto.getDisabilityNeeds())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getDisabilityNeeds())
                            .append("。");
                }
            } else {
                builder.append("残疾需求修改前:")
                        .append(oldDisabilityMsgDto.getDisabilityNeeds())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getDisabilityNeeds())) {
                builder.append("残疾需求修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getDisabilityNeeds())
                        .append("。");
            }
        }
        //残疾人信息-个人技能
        if (StringUtils.hasText(oldDisabilityMsgDto.getPersonalSkills())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getPersonalSkills())) {
                if (!oldDisabilityMsgDto.getPersonalSkills().equals(newDisabilityMsgDto.getPersonalSkills())) {
                    builder.append("个人技能修改前:")
                            .append(oldDisabilityMsgDto.getPersonalSkills())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getPersonalSkills())
                            .append("。");
                }
            } else {
                builder.append("个人技能修改前:")
                        .append(oldDisabilityMsgDto.getPersonalSkills())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getPersonalSkills())) {
                builder.append("个人技能修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getPersonalSkills())
                        .append("。");
            }
        }
        //残疾人信息-护理补贴
        if (StringUtils.hasText(oldDisabilityMsgDto.getCare())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getCare())) {
                if (!oldDisabilityMsgDto.getCare().equals(newDisabilityMsgDto.getCare())) {
                    builder.append("护理补贴修改前:")
                            .append(oldDisabilityMsgDto.getCare())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getCare())
                            .append("。");
                }
            } else {
                builder.append("护理补贴修改前:")
                        .append(oldDisabilityMsgDto.getCare())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getCare())) {
                builder.append("护理补贴修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getCare())
                        .append("。");
            }
        }
        //残疾人信息-生活补贴
        if (StringUtils.hasText(oldDisabilityMsgDto.getLife())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getLife())) {
                if (!oldDisabilityMsgDto.getLife().equals(newDisabilityMsgDto.getLife())) {
                    builder.append("生活补贴修改前:")
                            .append(oldDisabilityMsgDto.getLife())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getLife())
                            .append("。");
                }
            } else {
                builder.append("生活补贴修改前:")
                        .append(oldDisabilityMsgDto.getLife())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getLife())) {
                builder.append("生活补贴修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getLife())
                        .append("。");
            }
        }
        //残疾人信息-其他备注
        if (StringUtils.hasText(oldDisabilityMsgDto.getRemark())) {
            if (StringUtils.hasText(newDisabilityMsgDto.getRemark())) {
                if (!oldDisabilityMsgDto.getRemark().equals(newDisabilityMsgDto.getRemark())) {
                    builder.append("其他备注修改前:")
                            .append(oldDisabilityMsgDto.getRemark())
                            .append(",修改后:")
                            .append(newDisabilityMsgDto.getRemark())
                            .append("。");
                }
            } else {
                builder.append("其他备注修改前:")
                        .append(oldDisabilityMsgDto.getRemark())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newDisabilityMsgDto.getRemark())) {
                builder.append("其他备注修改前:无")
                        .append(",修改后:")
                        .append(newDisabilityMsgDto.getRemark())
                        .append("。");
            }
        }
        builder.append("}");

        //低保户信息
        String oldUnderProtect = oldPerson.getUnderProtect();
        SubsistenceMsgDto oldSubsistenceMsgDto = JSON.parseObject(oldUnderProtect, SubsistenceMsgDto.class);
        String newUnderProtect = newPerson.getUnderProtect();
        SubsistenceMsgDto newSubsistenceMsgDto = JSON.parseObject(newUnderProtect, SubsistenceMsgDto.class);
        builder.append("低保户信息:{");
        //低保户信息-领取证号
        if (StringUtils.hasText(oldSubsistenceMsgDto.getCertificateNo())) {
            if (StringUtils.hasText(newSubsistenceMsgDto.getCertificateNo())) {
                if (!oldSubsistenceMsgDto.getCertificateNo().equals(newSubsistenceMsgDto.getCertificateNo())) {
                    builder.append("领取证号修改前:")
                            .append(oldSubsistenceMsgDto.getCertificateNo())
                            .append(",修改后:")
                            .append(newSubsistenceMsgDto.getCertificateNo())
                            .append("。");
                }
            } else {
                builder.append("领取证号修改前:")
                        .append(oldSubsistenceMsgDto.getCertificateNo())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSubsistenceMsgDto.getCertificateNo())) {
                builder.append("领取证号修改前:无")
                        .append(",修改后:")
                        .append(newSubsistenceMsgDto.getCertificateNo())
                        .append("。");
            }
        }
        //低保户信息-金额
        if (StringUtils.hasText(oldSubsistenceMsgDto.getAmount())) {
            if (StringUtils.hasText(newSubsistenceMsgDto.getAmount())) {
                if (!oldSubsistenceMsgDto.getAmount().equals(newSubsistenceMsgDto.getAmount())) {
                    builder.append("金额修改前:")
                            .append(oldSubsistenceMsgDto.getAmount())
                            .append(",修改后:")
                            .append(newSubsistenceMsgDto.getAmount())
                            .append("。");
                }
            } else {
                builder.append("金额修改前:")
                        .append(oldSubsistenceMsgDto.getAmount())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSubsistenceMsgDto.getAmount())) {
                builder.append("金额修改前:无")
                        .append(",修改后:")
                        .append(newSubsistenceMsgDto.getAmount())
                        .append("。");
            }
        }
        //低保户信息-低保类型
        if (StringUtils.hasText(oldSubsistenceMsgDto.getType())) {
            if (StringUtils.hasText(newSubsistenceMsgDto.getType())) {
                if (!oldSubsistenceMsgDto.getType().equals(newSubsistenceMsgDto.getType())) {
                    builder.append("低保类型修改前:")
                            .append(oldSubsistenceMsgDto.getType())
                            .append(",修改后:")
                            .append(newSubsistenceMsgDto.getType())
                            .append("。");
                }
            } else {
                builder.append("低保类型修改前:")
                        .append(oldSubsistenceMsgDto.getType())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSubsistenceMsgDto.getType())) {
                builder.append("低保类型修改前:无")
                        .append(",修改后:")
                        .append(newSubsistenceMsgDto.getType())
                        .append("。");
            }
        }
        //低保户信息-审批时间
        if (oldSubsistenceMsgDto.getApprovalTime() != null) {
            if (newSubsistenceMsgDto.getApprovalTime() != null) {
                if (!format.format(oldSubsistenceMsgDto.getApprovalTime()).equals(format.format(newSubsistenceMsgDto.getApprovalTime()))) {
                    builder.append("审批时间修改前:")
                            .append(format.format(oldSubsistenceMsgDto.getApprovalTime()))
                            .append(",修改后:")
                            .append(format.format(newSubsistenceMsgDto.getApprovalTime()))
                            .append("。");
                }
            } else {
                builder.append("审批时间修改前:")
                        .append(format.format(oldSubsistenceMsgDto.getApprovalTime()))
                        .append(",修改后:无")
                        .append("。");
            }

        } else {
            if (newSubsistenceMsgDto.getApprovalTime() != null) {
                if (StringUtils.hasText(format.format(newSubsistenceMsgDto.getApprovalTime()))) {
                    builder.append("审批时间修改前:无")
                            .append(",修改后:")
                            .append(format.format(newSubsistenceMsgDto.getApprovalTime()))
                            .append("。");
                }
            }
        }
        //低保户信息-生活状态
        if (StringUtils.hasText(oldSubsistenceMsgDto.getLivingState())) {
            if (StringUtils.hasText(newSubsistenceMsgDto.getLivingState())) {
                if (!oldSubsistenceMsgDto.getLivingState().equals(newSubsistenceMsgDto.getLivingState())) {
                    builder.append("生活状态修改前:")
                            .append(oldSubsistenceMsgDto.getLivingState())
                            .append(",修改后:")
                            .append(newSubsistenceMsgDto.getLivingState())
                            .append("。");
                }
            } else {
                builder.append("生活状态修改前:")
                        .append(oldSubsistenceMsgDto.getLivingState())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSubsistenceMsgDto.getLivingState())) {
                builder.append("生活状态修改前:无")
                        .append(",修改后:")
                        .append(newSubsistenceMsgDto.getLivingState())
                        .append("。");
            }
        }
        //低保户信息-致贫原因
        if (StringUtils.hasText(oldSubsistenceMsgDto.getCausesOfPoverty())) {
            if (StringUtils.hasText(newSubsistenceMsgDto.getCausesOfPoverty())) {
                if (!oldSubsistenceMsgDto.getCausesOfPoverty().equals(newSubsistenceMsgDto.getCausesOfPoverty())) {
                    builder.append("致贫原因修改前:")
                            .append(oldSubsistenceMsgDto.getCausesOfPoverty())
                            .append(",修改后:")
                            .append(newSubsistenceMsgDto.getCausesOfPoverty())
                            .append("。");
                }
            } else {
                builder.append("致贫原因修改前:")
                        .append(oldSubsistenceMsgDto.getCausesOfPoverty())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSubsistenceMsgDto.getCausesOfPoverty())) {
                builder.append("致贫原因修改前:无")
                        .append(",修改后:")
                        .append(newSubsistenceMsgDto.getCausesOfPoverty())
                        .append("。");
            }
        }
        //低保户信息-其他备注
        if (StringUtils.hasText(oldSubsistenceMsgDto.getRemark())) {
            if (StringUtils.hasText(newSubsistenceMsgDto.getRemark())) {
                if (!oldSubsistenceMsgDto.getRemark().equals(newSubsistenceMsgDto.getRemark())) {
                    builder.append("其他备注修改前:")
                            .append(oldSubsistenceMsgDto.getRemark())
                            .append(",修改后:")
                            .append(newSubsistenceMsgDto.getRemark())
                            .append("。");
                }
            } else {
                builder.append("其他备注修改前:")
                        .append(oldSubsistenceMsgDto.getRemark())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSubsistenceMsgDto.getRemark())) {
                builder.append("其他备注修改前:无")
                        .append(",修改后:")
                        .append(newSubsistenceMsgDto.getRemark())
                        .append("。");
            }
        }
        builder.append("}");

        //优抚信息
        String oldCareMan = oldPerson.getCareMan();
        SpecialMsgDto oldSpecialMsgDto = JSON.parseObject(oldCareMan, SpecialMsgDto.class);
        String newCareMan = newPerson.getCareMan();
        SpecialMsgDto newSpecialMsgDto = JSON.parseObject(newCareMan, SpecialMsgDto.class);
        builder.append("优抚信息:{");
        //优抚信息-类别
        if (StringUtils.hasText(oldSpecialMsgDto.getCategory())) {
            if (StringUtils.hasText(newSpecialMsgDto.getCategory())) {
                if (!oldSpecialMsgDto.getCategory().equals(newSpecialMsgDto.getCategory())) {
                    builder.append("类别修改前:")
                            .append(oldSpecialMsgDto.getCategory())
                            .append(",修改后:")
                            .append(newSpecialMsgDto.getCategory())
                            .append("。");
                }
            } else {
                builder.append("类别修改前:")
                        .append(oldSpecialMsgDto.getCategory())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSpecialMsgDto.getCategory())) {
                builder.append("类别修改前:无")
                        .append(",修改后:")
                        .append(newSpecialMsgDto.getCategory())
                        .append("。");
            }
        }
        //优抚信息-重点优抚对象
        if (StringUtils.hasText(oldSpecialMsgDto.getEntitledGroups())) {
            if (StringUtils.hasText(newSpecialMsgDto.getEntitledGroups())) {
                if (!oldSpecialMsgDto.getEntitledGroups().equals(newSpecialMsgDto.getEntitledGroups())) {
                    builder.append("重点优抚对象修改前:")
                            .append(oldSpecialMsgDto.getEntitledGroups())
                            .append(",修改后:")
                            .append(newSpecialMsgDto.getEntitledGroups())
                            .append("。");
                }
            } else {
                builder.append("重点优抚对象修改前:")
                        .append(oldSpecialMsgDto.getEntitledGroups())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSpecialMsgDto.getEntitledGroups())) {
                builder.append("重点优抚对象修改前:无")
                        .append(",修改后:")
                        .append(newSpecialMsgDto.getEntitledGroups())
                        .append("。");
            }
        }
        //优抚信息-服役部队
        if (StringUtils.hasText(oldSpecialMsgDto.getServiceTroops())) {
            if (StringUtils.hasText(newSpecialMsgDto.getServiceTroops())) {
                if (!oldSpecialMsgDto.getServiceTroops().equals(newSpecialMsgDto.getServiceTroops())) {
                    builder.append("服役部队修改前:")
                            .append(oldSpecialMsgDto.getServiceTroops())
                            .append(",修改后:")
                            .append(newSpecialMsgDto.getServiceTroops())
                            .append("。");
                }
            } else {
                builder.append("服役部队修改前:")
                        .append(oldSpecialMsgDto.getServiceTroops())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSpecialMsgDto.getServiceTroops())) {
                builder.append("服役部队修改前:无")
                        .append(",修改后:")
                        .append(newSpecialMsgDto.getServiceTroops())
                        .append("。");
            }
        }
        //优抚信息-入伍时间
        if (oldSpecialMsgDto.getEnlistmentTime() != null) {
            if (newSpecialMsgDto.getEnlistmentTime() != null) {
                if (!format.format(oldSpecialMsgDto.getEnlistmentTime()).equals(format.format(newSpecialMsgDto.getEnlistmentTime()))) {
                    builder.append("入伍时间修改前:")
                            .append(format.format(oldSpecialMsgDto.getEnlistmentTime()))
                            .append(",修改后:")
                            .append(format.format(newSpecialMsgDto.getEnlistmentTime()))
                            .append("。");
                }
            } else {
                builder.append("入伍时间修改前:")
                        .append(format.format(oldSpecialMsgDto.getEnlistmentTime()))
                        .append(",修改后:无")
                        .append("。");
            }

        } else {
            if (newSpecialMsgDto.getEnlistmentTime() != null) {
                if (StringUtils.hasText(format.format(newSpecialMsgDto.getEnlistmentTime()))) {
                    builder.append("入伍时间修改前:无")
                            .append(",修改后:")
                            .append(format.format(newSpecialMsgDto.getEnlistmentTime()))
                            .append("。");
                }
            }
        }
        //优抚信息-退伍时间
        if (oldSpecialMsgDto.getDemobilizationTime() != null) {
            if (newSpecialMsgDto.getDemobilizationTime() != null) {
                if (!format.format(oldSpecialMsgDto.getDemobilizationTime()).equals(format.format(newSpecialMsgDto.getDemobilizationTime()))) {
                    builder.append("退伍时间修改前:")
                            .append(format.format(oldSpecialMsgDto.getDemobilizationTime()))
                            .append(",修改后:")
                            .append(format.format(newSpecialMsgDto.getDemobilizationTime()))
                            .append("。");
                }
            } else {
                builder.append("退伍时间修改前:")
                        .append(format.format(oldSpecialMsgDto.getDemobilizationTime()))
                        .append(",修改后:无")
                        .append("。");
            }

        } else {
            if (newSpecialMsgDto.getDemobilizationTime() != null) {
                if (StringUtils.hasText(format.format(newSpecialMsgDto.getDemobilizationTime()))) {
                    builder.append("退伍时间修改前:无")
                            .append(",修改后:")
                            .append(format.format(newSpecialMsgDto.getDemobilizationTime()))
                            .append("。");
                }
            }
        }
        //优抚信息-安置情况
        if (StringUtils.hasText(oldSpecialMsgDto.getResettlement())) {
            if (StringUtils.hasText(newSpecialMsgDto.getResettlement())) {
                if (!oldSpecialMsgDto.getResettlement().equals(newSpecialMsgDto.getResettlement())) {
                    builder.append("安置情况修改前:")
                            .append(oldSpecialMsgDto.getResettlement())
                            .append(",修改后:")
                            .append(newSpecialMsgDto.getResettlement())
                            .append("。");
                }
            } else {
                builder.append("安置情况修改前:")
                        .append(oldSpecialMsgDto.getResettlement())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSpecialMsgDto.getResettlement())) {
                builder.append("安置情况修改前:无")
                        .append(",修改后:")
                        .append(newSpecialMsgDto.getResettlement())
                        .append("。");
            }
        }
        //优抚信息-参保情况
        if (StringUtils.hasText(oldSpecialMsgDto.getInsured())) {
            if (StringUtils.hasText(newSpecialMsgDto.getInsured())) {
                if (!oldSpecialMsgDto.getInsured().equals(newSpecialMsgDto.getInsured())) {
                    builder.append("参保情况修改前:")
                            .append(oldSpecialMsgDto.getInsured())
                            .append(",修改后:")
                            .append(newSpecialMsgDto.getInsured())
                            .append("。");
                }
            } else {
                builder.append("参保情况修改前:")
                        .append(oldSpecialMsgDto.getInsured())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSpecialMsgDto.getInsured())) {
                builder.append("参保情况修改前:无")
                        .append(",修改后:")
                        .append(newSpecialMsgDto.getInsured())
                        .append("。");
            }
        }
        //优抚信息-再就业情况
        if (StringUtils.hasText(oldSpecialMsgDto.getReemployment())) {
            if (StringUtils.hasText(newSpecialMsgDto.getReemployment())) {
                if (!oldSpecialMsgDto.getReemployment().equals(newSpecialMsgDto.getReemployment())) {
                    builder.append("再就业情况修改前:")
                            .append(oldSpecialMsgDto.getReemployment())
                            .append(",修改后:")
                            .append(newSpecialMsgDto.getReemployment())
                            .append("。");
                }
            } else {
                builder.append("再就业情况修改前:")
                        .append(oldSpecialMsgDto.getReemployment())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSpecialMsgDto.getReemployment())) {
                builder.append("再就业情况修改前:无")
                        .append(",修改后:")
                        .append(newSpecialMsgDto.getReemployment())
                        .append("。");
            }
        }
        //优抚信息-立功受奖
        if (StringUtils.hasText(oldSpecialMsgDto.getAward())) {
            if (StringUtils.hasText(newSpecialMsgDto.getAward())) {
                if (!oldSpecialMsgDto.getAward().equals(newSpecialMsgDto.getAward())) {
                    builder.append("立功受奖修改前:")
                            .append(oldSpecialMsgDto.getAward())
                            .append(",修改后:")
                            .append(newSpecialMsgDto.getAward())
                            .append("。");
                }
            } else {
                builder.append("立功受奖修改前:")
                        .append(oldSpecialMsgDto.getAward())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSpecialMsgDto.getAward())) {
                builder.append("立功受奖修改前:无")
                        .append(",修改后:")
                        .append(newSpecialMsgDto.getAward())
                        .append("。");
            }
        }
        //优抚信息-其他备注
        if (StringUtils.hasText(oldSpecialMsgDto.getRemark())) {
            if (StringUtils.hasText(newSpecialMsgDto.getRemark())) {
                if (!oldSpecialMsgDto.getRemark().equals(newSpecialMsgDto.getRemark())) {
                    builder.append("其他备注修改前:")
                            .append(oldSpecialMsgDto.getRemark())
                            .append(",修改后:")
                            .append(newSpecialMsgDto.getRemark())
                            .append("。");
                }
            } else {
                builder.append("其他备注修改前:")
                        .append(oldSpecialMsgDto.getRemark())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newSpecialMsgDto.getRemark())) {
                builder.append("其他备注修改前:无")
                        .append(",修改后:")
                        .append(newSpecialMsgDto.getRemark())
                        .append("。");
            }
        }
        builder.append("}");

        //党员信息
        String oldPartMan = oldPerson.getPartMan();
        MemberMsgDto oldMemberMsgDto = JSON.parseObject(oldPartMan, MemberMsgDto.class);
        String newPartMan = newPerson.getPartMan();
        MemberMsgDto newMemberMsgDto = JSON.parseObject(newPartMan, MemberMsgDto.class);
        builder.append("党员信息:{");
        //党员信息-入党日期
        if (oldMemberMsgDto.getJoinPartyTime() != null) {
            if (newMemberMsgDto.getJoinPartyTime() != null) {
                if (!format.format(oldMemberMsgDto.getJoinPartyTime()).equals(format.format(newMemberMsgDto.getJoinPartyTime()))) {
                    builder.append("入党日期修改前:")
                            .append(format.format(oldMemberMsgDto.getJoinPartyTime()))
                            .append(",修改后:")
                            .append(format.format(newMemberMsgDto.getJoinPartyTime()))
                            .append("。");
                }
            } else {
                builder.append("入党日期修改前:")
                        .append(format.format(oldMemberMsgDto.getJoinPartyTime()))
                        .append(",修改后:无")
                        .append("。");
            }

        } else {
            if (newMemberMsgDto.getJoinPartyTime() != null) {
                if (StringUtils.hasText(format.format(newMemberMsgDto.getJoinPartyTime()))) {
                    builder.append("入党日期修改前:无")
                            .append(",修改后:")
                            .append(format.format(newMemberMsgDto.getJoinPartyTime()))
                            .append("。");
                }
            }
        }
        //党员信息-转入时间
        if (oldMemberMsgDto.getShiftToTime() != null) {
            if (newMemberMsgDto.getShiftToTime() != null) {
                if (!format.format(oldMemberMsgDto.getShiftToTime()).equals(format.format(newMemberMsgDto.getShiftToTime()))) {
                    builder.append("转入时间修改前:")
                            .append(format.format(oldMemberMsgDto.getShiftToTime()))
                            .append(",修改后:")
                            .append(format.format(newMemberMsgDto.getShiftToTime()))
                            .append("。");
                }
            } else {
                builder.append("转入时间修改前:")
                        .append(format.format(oldMemberMsgDto.getShiftToTime()))
                        .append(",修改后:无")
                        .append("。");
            }

        } else {
            if (newMemberMsgDto.getShiftToTime() != null) {
                if (StringUtils.hasText(format.format(newMemberMsgDto.getShiftToTime()))) {
                    builder.append("转入时间修改前:无")
                            .append(",修改后:")
                            .append(format.format(newMemberMsgDto.getShiftToTime()))
                            .append("。");
                }
            }
        }
        //党员信息-转出时间
        if (oldMemberMsgDto.getShiftOutTime() != null) {
            if (newMemberMsgDto.getShiftOutTime() != null) {
                if (!format.format(oldMemberMsgDto.getShiftOutTime()).equals(format.format(newMemberMsgDto.getShiftOutTime()))) {
                    builder.append("转出时间修改前:")
                            .append(format.format(oldMemberMsgDto.getShiftOutTime()))
                            .append(",修改后:")
                            .append(format.format(newMemberMsgDto.getShiftOutTime()))
                            .append("。");
                }
            } else {
                builder.append("转出时间修改前:")
                        .append(format.format(oldMemberMsgDto.getShiftOutTime()))
                        .append(",修改后:无")
                        .append("。");
            }

        } else {
            if (newMemberMsgDto.getShiftOutTime() != null) {
                if (StringUtils.hasText(format.format(newMemberMsgDto.getShiftOutTime()))) {
                    builder.append("转出时间修改前:无")
                            .append(",修改后:")
                            .append(format.format(newMemberMsgDto.getShiftOutTime()))
                            .append("。");
                }
            }
        }
        //党员信息-党内职务
        if (StringUtils.hasText(oldMemberMsgDto.getPartyPosts())) {
            if (StringUtils.hasText(newMemberMsgDto.getPartyPosts())) {
                if (!oldMemberMsgDto.getPartyPosts().equals(newMemberMsgDto.getPartyPosts())) {
                    builder.append("党内职务修改前:")
                            .append(oldMemberMsgDto.getPartyPosts())
                            .append(",修改后:")
                            .append(newMemberMsgDto.getPartyPosts())
                            .append("。");
                }
            } else {
                builder.append("党内职务修改前:")
                        .append(oldMemberMsgDto.getPartyPosts())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMemberMsgDto.getPartyPosts())) {
                builder.append("党内职务修改前:无")
                        .append(",修改后:")
                        .append(newMemberMsgDto.getPartyPosts())
                        .append("。");
            }
        }
        //党员信息-党员类别
        if (StringUtils.hasText(oldMemberMsgDto.getPartyManCategory())) {
            if (StringUtils.hasText(newMemberMsgDto.getPartyManCategory())) {
                if (!oldMemberMsgDto.getPartyManCategory().equals(newMemberMsgDto.getPartyManCategory())) {
                    builder.append("党员类别修改前:")
                            .append(oldMemberMsgDto.getPartyManCategory())
                            .append(",修改后:")
                            .append(newMemberMsgDto.getPartyManCategory())
                            .append("。");
                }
            } else {
                builder.append("党员类别修改前:")
                        .append(oldMemberMsgDto.getPartyManCategory())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMemberMsgDto.getPartyManCategory())) {
                builder.append("党员类别修改前:无")
                        .append(",修改后:")
                        .append(newMemberMsgDto.getPartyManCategory())
                        .append("。");
            }
        }
        //党员信息-党费基数
        if (StringUtils.hasText(oldMemberMsgDto.getPartyExpenditureBase())) {
            if (StringUtils.hasText(newMemberMsgDto.getPartyExpenditureBase())) {
                if (!oldMemberMsgDto.getPartyExpenditureBase().equals(newMemberMsgDto.getPartyExpenditureBase())) {
                    builder.append("党费基数修改前:")
                            .append(oldMemberMsgDto.getPartyExpenditureBase())
                            .append(",修改后:")
                            .append(newMemberMsgDto.getPartyExpenditureBase())
                            .append("。");
                }
            } else {
                builder.append("党费基数修改前:")
                        .append(oldMemberMsgDto.getPartyExpenditureBase())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMemberMsgDto.getPartyExpenditureBase())) {
                builder.append("党费基数修改前:无")
                        .append(",修改后:")
                        .append(newMemberMsgDto.getPartyExpenditureBase())
                        .append("。");
            }
        }
        //党员信息-原工作单位
        if (StringUtils.hasText(oldMemberMsgDto.getOriginalWorkUnit())) {
            if (StringUtils.hasText(newMemberMsgDto.getOriginalWorkUnit())) {
                if (!oldMemberMsgDto.getOriginalWorkUnit().equals(newMemberMsgDto.getOriginalWorkUnit())) {
                    builder.append("原工作单位修改前:")
                            .append(oldMemberMsgDto.getOriginalWorkUnit())
                            .append(",修改后:")
                            .append(newMemberMsgDto.getOriginalWorkUnit())
                            .append("。");
                }
            } else {
                builder.append("原工作单位修改前:")
                        .append(oldMemberMsgDto.getOriginalWorkUnit())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMemberMsgDto.getOriginalWorkUnit())) {
                builder.append("原工作单位修改前:无")
                        .append(",修改后:")
                        .append(newMemberMsgDto.getOriginalWorkUnit())
                        .append("。");
            }
        }
        //党员信息-其他备注
        if (StringUtils.hasText(oldMemberMsgDto.getRemark())) {
            if (StringUtils.hasText(newMemberMsgDto.getRemark())) {
                if (!oldMemberMsgDto.getRemark().equals(newMemberMsgDto.getRemark())) {
                    builder.append("其他备注修改前:")
                            .append(oldMemberMsgDto.getRemark())
                            .append(",修改后:")
                            .append(newMemberMsgDto.getRemark())
                            .append("。");
                }
            } else {
                builder.append("其他备注修改前:")
                        .append(oldMemberMsgDto.getRemark())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newMemberMsgDto.getRemark())) {
                builder.append("其他备注修改前:无")
                        .append(",修改后:")
                        .append(newMemberMsgDto.getRemark())
                        .append("。");
            }
        }
        builder.append("}");

        //租户信息
        String oldTenant = oldPerson.getTenant();
        TenantMsgDto oldTenantMsgDto = JSON.parseObject(oldTenant, TenantMsgDto.class);
        String newTenant = newPerson.getTenant();
        TenantMsgDto newTenantMsgDto = JSON.parseObject(newTenant, TenantMsgDto.class);
        builder.append("租户信息:{");
        //租户信息-租期
        if (StringUtils.hasText(oldTenantMsgDto.getTenancy())) {
            if (StringUtils.hasText(newTenantMsgDto.getTenancy())) {
                if (!oldTenantMsgDto.getTenancy().equals(newTenantMsgDto.getTenancy())) {
                    builder.append("租期修改前:")
                            .append(oldTenantMsgDto.getTenancy())
                            .append(",修改后:")
                            .append(newTenantMsgDto.getTenancy())
                            .append("。");
                }
            } else {
                builder.append("租期修改前:")
                        .append(oldTenantMsgDto.getTenancy())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newTenantMsgDto.getTenancy())) {
                builder.append("租期修改前:无")
                        .append(",修改后:")
                        .append(newTenantMsgDto.getTenancy())
                        .append("。");
            }
        }
        //租户信息-办理居住证
        if (StringUtils.hasText(oldTenantMsgDto.getResidencePermit())) {
            if (StringUtils.hasText(newTenantMsgDto.getResidencePermit())) {
                if (!oldTenantMsgDto.getResidencePermit().equals(newTenantMsgDto.getResidencePermit())) {
                    builder.append("办理居住证修改前:")
                            .append(oldTenantMsgDto.getResidencePermit())
                            .append(",修改后:")
                            .append(newTenantMsgDto.getResidencePermit())
                            .append("。");
                }
            } else {
                builder.append("办理居住证修改前:")
                        .append(oldTenantMsgDto.getResidencePermit())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newTenantMsgDto.getResidencePermit())) {
                builder.append("办理居住证修改前:无")
                        .append(",修改后:")
                        .append(newTenantMsgDto.getResidencePermit())
                        .append("。");
            }
        }
        //租户信息-办理流动人口证
        if (StringUtils.hasText(oldTenantMsgDto.getFloatingPopulation())) {
            if (StringUtils.hasText(newTenantMsgDto.getFloatingPopulation())) {
                if (!oldTenantMsgDto.getFloatingPopulation().equals(newTenantMsgDto.getFloatingPopulation())) {
                    builder.append("办理流动人口证修改前:")
                            .append(oldTenantMsgDto.getFloatingPopulation())
                            .append(",修改后:")
                            .append(newTenantMsgDto.getFloatingPopulation())
                            .append("。");
                }
            } else {
                builder.append("办理流动人口证修改前:")
                        .append(oldTenantMsgDto.getFloatingPopulation())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newTenantMsgDto.getFloatingPopulation())) {
                builder.append("办理流动人口证修改前:无")
                        .append(",修改后:")
                        .append(newTenantMsgDto.getFloatingPopulation())
                        .append("。");
            }
        }
        //租户信息-其他备注
        if (StringUtils.hasText(oldTenantMsgDto.getRemark())) {
            if (StringUtils.hasText(newTenantMsgDto.getRemark())) {
                if (!oldTenantMsgDto.getRemark().equals(newTenantMsgDto.getRemark())) {
                    builder.append("其他备注修改前:")
                            .append(oldTenantMsgDto.getRemark())
                            .append(",修改后:")
                            .append(newTenantMsgDto.getRemark())
                            .append("。");
                }
            } else {
                builder.append("其他备注修改前:")
                        .append(oldTenantMsgDto.getRemark())
                        .append(",修改后:无")
                        .append("。");
            }
        } else {
            if (StringUtils.hasText(newTenantMsgDto.getRemark())) {
                builder.append("其他备注修改前:无")
                        .append(",修改后:")
                        .append(newTenantMsgDto.getRemark())
                        .append("。");
            }
        }
        builder.append("}");
        return builder;
    }
}
